shithub: musw

Download patch

ref: 8731378bba72cf2a5084f90fb375c998f2be6472
parent: 75dfc00c40c6d811143b3dfaca865e3caa48db68
author: rodri <rgl@antares-labs.eu>
date: Sun Aug 1 12:39:55 EDT 2021

added an sprite for the Earth.

diff: cannot open b/assets/spr//null: file does not exist: 'b/assets/spr//null'
binary files /dev/null b/assets/spr/earth.pic differ
--- a/dat.h
+++ b/dat.h
@@ -93,7 +93,7 @@
 struct Star
 {
 	Particle;
-	Sprite spr;
+	Sprite *spr;
 };
 
 struct Universe
--- a/fns.h
+++ b/fns.h
@@ -43,3 +43,10 @@
 Universe *newuniverse(void);
 void deluniverse(Universe*);
 void inituniverse(Universe*);
+
+/*
+ *	sprite
+ */
+Sprite *newsprite(Image*, Point, Rectangle, int, ulong);
+Sprite *readsprite(char*, Point, Rectangle, int, ulong);
+void delsprite(Sprite*);
--- a/mkfile
+++ b/mkfile
@@ -13,8 +13,8 @@
 	pack.$O\
 	lobby.$O\
 	party.$O\
-	sprite.$O\
 	universe.$O\
+	sprite.$O\
 
 HFILES=\
 	dat.h\
--- a/musw.c
+++ b/musw.c
@@ -244,7 +244,7 @@
 
 	drawship(&universe->ships[0], screen);
 	drawship(&universe->ships[1], screen);
-	fillellipse(screen, toscreen(universe->star.p), 4, 4, display->white, ZP);
+	universe->star.spr->draw(universe->star.spr, screen, subpt(toscreen(universe->star.p), Pt(16,16)));
 
 	flushimage(display, 1);
 	unlockdisplay(display);
@@ -287,6 +287,8 @@
 void
 threadmain(int argc, char *argv[])
 {
+	uvlong then, now;
+	double frametime;
 	char *server;
 	int fd;
 	Mousectl *mc;
@@ -330,13 +332,22 @@
 		sysfatal("readvmodel: %r");
 	universe->ships[0].mdl = needlemdl;
 	universe->ships[1].mdl = needlemdl;
+	universe->star.spr = readsprite("assets/spr/earth.pic", ZP, Rect(0,0,32,32), 5, 20e3);
 
 	threadcreate(threadnetrecv, &fd, 4096);
 	threadcreate(threadresize, mc, 4096);
 
+	then = nanosec();
 	io = ioproc();
 	for(;;){
+		now = nanosec();
+		frametime = now - then;
+		then = now;
+
+		universe->star.spr->step(universe->star.spr, frametime/1e6);
+
 		redraw();
+
 		iosleep(io, HZ2MS(30));
 	}
 }