10 // We use seconds for measuring time, meters for measuring distance
21 }TKeyBinding
;//TODO: s/int/real data type for a key
24 Vect Pos
; //where he is
25 Vect Move
; //how he want to move
26 Vect BSize
; //Size of bounding rect
27 Area
*Shape
; //how fat he is
28 //Area *TrShape; //translated Shape -- don't optimize yet
29 int Frags
; //no comment
31 double Speed
; //meters per second
32 int Orientation
; //1-up 2-left 3-down 4-right 0-down
33 int WannaShoot
; //1-want 0-don't want
34 double ReloadTime
; //time from last shot
35 int WannaDie
; //1-want suicide 2-died and still holding suicide 0-don't want
36 double AnimationTime
; //in seconds
49 int Exists
; // 0- doesn't exist 1-exists
59 Vect Vel
; //velocity i m/s
60 double Speed
; //for Templates
62 int lid
; //who shoot this bullet?
63 int Exists
; // 0- doesn't exist 1-exists
64 double SFuzzy
; // Fuzzy factor for spawning 0-1 :)
65 double VFuzzy
; // Fuzzy factor for traveling 0-1 :)
70 TMap
*Map
; //where we are playing
71 TLilanek
*Lilanek
; //our heroes-ehm bad guys
74 TWeapon
*Weapon
; //Weapons lying on floor
76 TWeapon
*WeaponTemplate
;
77 TBullet
*BulletTemplate
;
78 int noWID
; //biggest WID, also number of WeaponTemplates
81 double PWeapondrop
; // Probability of weapon drop per second
86 void SwitchNextWeapon(Game
*g
, int lid
);
104 void SpawnLilanek(Game
*g
, int lid
){
113 for(tries
=0; tries
<1000; tries
++){ //TODO: remove exact number
114 Pos
.x
= RandD(0,g
->Map
->XX
);
115 Pos
.y
= RandD(0,g
->Map
->YY
);
117 tp
= TranslateArea(g
->Lilanek
[lid
].Shape
, &Pos
);
118 printf("%s\n", Area2String(tp
));
119 if(!AreaInMap(g
->Map
, tp
,0,1)){
123 for(olid
=0; olid
< g
->noLilaneks
; olid
++){
126 if(!g
->Lilanek
[olid
].Alive
){
129 oltp
= TranslateArea(g
->Lilanek
[olid
].Shape
, &g
->Lilanek
[olid
].Pos
);
130 if(AreaInArea(tp
, oltp
)){
140 g
->Lilanek
[lid
].Pos
.x
= Pos
.x
;
141 g
->Lilanek
[lid
].Pos
.y
= Pos
.y
;
142 g
->Lilanek
[lid
].Alive
= 1;
150 void DropWeapon(Game
*g
, int weapon
){
156 for(tries
=0; tries
<100; tries
++){ //TODO: remove exact number
157 Pos
.x
= RandD(0,g
->Map
->XX
);
158 Pos
.y
= RandD(0,g
->Map
->YY
);
159 WID
= RandI(0, g
->noWID
);
160 tp
= TranslateArea(g
->WeaponTemplate
[WID
].Shape
, &Pos
);
161 if(AreaInMap(g
->Map
, tp
, 0, g
->Map
->noLayer
)){
164 memcpy(&g
->Weapon
[weapon
], &g
->WeaponTemplate
[WID
], sizeof(TWeapon
));
165 g
->Weapon
[weapon
].Shape
= g
->WeaponTemplate
[WID
].Shape
;
166 g
->Weapon
[weapon
].Pos
.x
= Pos
.x
;
167 g
->Weapon
[weapon
].Pos
.y
= Pos
.y
;
168 g
->Weapon
[weapon
].WID
= WID
;
169 g
->Weapon
[weapon
].Exists
= 1;
177 void DropWeapons(Game
*g
, double dtime
){
181 if( RandD(0.0, 1.0) >= (g
->PWeapondrop
*dtime
))
183 for(i
=0; i
< g
->noWeapons
; i
++){
184 if(g
->Weapon
[i
].Exists
)continue; //we don't like teleporting weapons :)
186 printf("A Weapon drop!\n");
188 break; //spawn max one weapon per update
192 void WeaponPickedUp(Game
*g
, double dtime
, int lid
, int wid
){
196 l
= &g
->Lilanek
[lid
];
199 l
->Ammo
[w
->WID
] += w
->Ammo
;
200 if(l
->Ammo
[w
->WID
] > w
->MaxAmmo
)
201 l
->Ammo
[w
->WID
] = w
->MaxAmmo
;
202 printf("Ammo: %d\n",l
->Ammo
[w
->WID
]);
203 l
->ActiveWeapon
= w
->WID
;
204 printf("AW: %d\n",l
->ActiveWeapon
);
210 void PickUpWeapons(Game
*g
, double dtime
){
214 for(lid
=0; lid
<g
->noLilaneks
; lid
++){
215 LArea
= TranslateArea(g
->Lilanek
[lid
].Shape
, &g
->Lilanek
[lid
].Pos
);
216 for(wid
=0; wid
< g
->noWeapons
; wid
++){
217 if(!g
->Weapon
[wid
].Exists
)
219 WArea
= TranslateArea(g
->Weapon
[wid
].Shape
, &g
->Weapon
[wid
].Pos
);
220 if(!AreaInArea( WArea
, LArea
)){
224 WeaponPickedUp(g
, dtime
, lid
, wid
);
231 void BulletExplodes(Game
*g
, int i
){
232 g
->Bullet
[i
].Exists
=0;
236 void MoveBullet(Game
*g
, double dtime
, int i
){
238 ff
= g
->Bullet
[i
].Speed
*g
->Bullet
[i
].VFuzzy
;
239 g
->Bullet
[i
].Pos
.x
+= (g
->Bullet
[i
].Vel
.x
+= RandD(-ff
,ff
))* dtime
;
240 g
->Bullet
[i
].Pos
.y
+= (g
->Bullet
[i
].Vel
.y
+= RandD(-ff
,ff
))* dtime
;
243 void CollideBulletMap(Game
*g
, double dtime
, int i
){
246 p
=TranslateArea(g
->Bullet
[i
].Shape
, &g
->Bullet
[i
].Pos
);
247 if(AreaInMap(g
->Map
, p
, 1,1)==0)
248 BulletExplodes(g
, i
);
251 void LilanekKilled(Game
*g
, double dtime
, int BulletID
, int LilanekID
){
252 g
->Bullet
[BulletID
].Exists
= 0;
253 g
->Lilanek
[LilanekID
].Deaths
++;
254 g
->Lilanek
[g
->Bullet
[BulletID
].lid
].Frags
++;
255 SpawnLilanek(g
, LilanekID
);
258 void CollideBulletLilanek(Game
*g
, double dtime
, int BulletID
){
262 BArea
=TranslateArea(g
->Bullet
[BulletID
].Shape
, &g
->Bullet
[BulletID
].Pos
);
263 for(LilanekID
=0; LilanekID
<g
->noLilaneks
; LilanekID
++){
264 LArea
=TranslateArea(g
->Lilanek
[LilanekID
].Shape
, &g
->Lilanek
[LilanekID
].Pos
);
265 if(AreaInArea(LArea
,BArea
))
266 LilanekKilled(g
, dtime
, BulletID
, LilanekID
);
274 void UpdateBullets(Game
*g
, double dtime
){
276 for(BulletID
=0; BulletID
<g
->noBullets
; BulletID
++){
277 if(g
->Bullet
[BulletID
].Exists
==0)
278 continue; //We won't update non-existending bullets
279 MoveBullet(g
, dtime
, BulletID
);
280 CollideBulletMap(g
, dtime
, BulletID
);
281 CollideBulletLilanek(g
, dtime
, BulletID
);
285 int CheckLilanekvsLilaneks(Game
*g
, Area
*a
, int LilanekID
){ //returns 0 if he collides with others, 1 if it's OK to move there
291 for(i
=0; i
<g
->noLilaneks
&& rval
==1; i
++){
294 nb
= TranslateArea(g
->Lilanek
[i
].Shape
, &g
->Lilanek
[i
].Pos
);
295 if(AreaInArea(nb
, a
))
303 void MoveLilaneks(Game
*g
, double dtime
){
310 for(i
=0; i
<g
->noLilaneks
; i
++){
311 //skip this Lilanek if he doesn't wanna move
312 if(g
->Lilanek
[i
].Move
.x
== 0.0 && g
->Lilanek
[i
].Move
.y
== 0.0)
314 for(dt
=dtime
, steps
=0; steps
<4; dt
/=2.0, steps
++){ //TODO: get rid of exact number
316 va
.x
= g
->Lilanek
[i
].Pos
.x
+ dt
*g
->Lilanek
[i
].Move
.x
;
317 va
.y
= g
->Lilanek
[i
].Pos
.y
+ dt
*g
->Lilanek
[i
].Move
.y
;
318 FreeArea(pa
); //we don't want memory leaks
319 pa
= TranslateArea(g
->Lilanek
[i
].Shape
, &va
);
320 //check for collision with map
321 if(AreaInMap(g
->Map
, pa
, 0, 1)==0)
322 continue; //try smaller dt if he collided with map
323 //check for collision with other Lilaneks
324 if(CheckLilanekvsLilaneks(g
, pa
, i
)==0)
326 //move him if we got here
327 g
->Lilanek
[i
].Pos
.x
+= dt
*g
->Lilanek
[i
].Move
.x
;
328 g
->Lilanek
[i
].Pos
.y
+= dt
*g
->Lilanek
[i
].Move
.y
;
332 FreeArea(pa
); //For sure
337 void ParseInput(Game
*g
, double dtime
){
343 keystate
= SDL_GetKeyState(NULL
);
345 for(i
=0; i
< g
->noLilaneks
; i
++){
346 curlil
= &g
->Lilanek
[i
];
349 if(keystate
[curlil
->Keys
.Up
]){
350 curlil
->Orientation
= 1;
351 curlil
->Move
.x
= curlil
->Speed
* Orientations
[1].x
;
352 curlil
->Move
.y
= curlil
->Speed
* Orientations
[1].y
;
356 if(keystate
[curlil
->Keys
.Down
]){
357 curlil
->Orientation
= 3;
358 curlil
->Move
.x
= curlil
->Speed
* Orientations
[3].x
;
359 curlil
->Move
.y
= curlil
->Speed
* Orientations
[3].y
;
363 if(keystate
[curlil
->Keys
.Left
]){
364 curlil
->Orientation
= 2;
365 curlil
->Move
.x
= curlil
->Speed
* Orientations
[2].x
;
366 curlil
->Move
.y
= curlil
->Speed
* Orientations
[2].y
;
370 if(keystate
[curlil
->Keys
.Right
]){
371 curlil
->Orientation
= 4;
372 curlil
->Move
.x
= curlil
->Speed
* Orientations
[4].x
;
373 curlil
->Move
.y
= curlil
->Speed
* Orientations
[4].y
;
382 if(keystate
[curlil
->Keys
.Shoot
]){
383 curlil
->WannaShoot
= 1;
385 curlil
->WannaShoot
= 0;
388 if(keystate
[curlil
->Keys
.Suicide
]){
389 if(curlil
->WannaDie
!= 2){
390 curlil
->WannaDie
= 1;
393 curlil
->WannaDie
= 0;
396 if(keystate
[curlil
->Keys
.Switch
]){
397 if(!curlil
->SwitchLock
){
398 SwitchNextWeapon(g
, i
);
399 curlil
->SwitchLock
= 1;
402 curlil
->SwitchLock
= 0;
407 void SpawnBullet(Game
*g
, double dtime
, int lid
, int bid
){
410 double vx
, vy
; //because we need to spawn also mines with no velocity
413 LArea
= TranslateArea(g
->Lilanek
[lid
].Shape
, &g
->Lilanek
[lid
]. Pos
);
415 bt
= &g
->BulletTemplate
[g
->Lilanek
[lid
].ActiveWeapon
];
416 memcpy (b
, bt
, sizeof(TBullet
));
418 b
->Pos
.x
= g
->Lilanek
[lid
].Pos
.x
+g
->Lilanek
[lid
].BSize
.x
*0.5;
419 b
->Pos
.y
= g
->Lilanek
[lid
].Pos
.y
+g
->Lilanek
[lid
].BSize
.y
*0.5;
421 b
->Vel
.x
= Orientations
[g
->Lilanek
[lid
].Orientation
].x
* b
->Speed
+RandD(-b
->Speed
*b
->SFuzzy
, b
->Speed
*b
->SFuzzy
);
422 b
->Vel
.y
= Orientations
[g
->Lilanek
[lid
].Orientation
].y
* b
->Speed
+RandD(-b
->Speed
*b
->SFuzzy
, b
->Speed
*b
->SFuzzy
);
423 if(DotProduct(&b
->Vel
, &b
->Vel
) <=0.01){
424 vx
= -1*Orientations
[g
->Lilanek
[lid
].Orientation
].x
;
425 vy
= -1*Orientations
[g
->Lilanek
[lid
].Orientation
].y
;
432 BArea
= TranslateArea(b
->Shape
, &b
->Pos
);
433 if(!AreaInArea(BArea
, LArea
))
435 b
->Pos
.x
+= vx
* dtime
*0.5;
436 b
->Pos
.y
+= vy
* dtime
*0.5;
441 void Shoot(Game
*g
, double dtime
, int lid
){
445 for(i
=0; i
<g
->WeaponTemplate
[g
->Lilanek
[lid
].ActiveWeapon
].Burst
; i
++){
446 if(g
->Lilanek
[lid
].Ammo
[g
->Lilanek
[lid
].ActiveWeapon
] == 0)
448 for(bid
=0; bid
<g
->noBullets
; bid
++){
449 if(g
->Bullet
[bid
].Exists
)
451 SpawnBullet(g
, dtime
, lid
, bid
);
452 g
->Lilanek
[lid
].Ammo
[g
->Lilanek
[lid
].ActiveWeapon
]--;
453 g
->Lilanek
[lid
].ReloadTime
= 0;
459 void SwitchNextWeapon(Game
*g
, int lid
){
462 l
= &g
->Lilanek
[lid
];
463 for(i
= 1; i
< g
->noWID
; i
++){
464 if(l
->Ammo
[(l
->ActiveWeapon
+i
)%(g
->noWID
)]){
465 l
->ActiveWeapon
= (l
->ActiveWeapon
+i
)%(g
->noWID
);
471 void ShootIfTheyWantTo(Game
*g
, double dtime
){
474 for(lid
=0; lid
<g
->noLilaneks
; lid
++){
475 //if(!g->Lilanek[lid].Exists)
477 if(g
->Lilanek
[lid
].Ammo
[g
->Lilanek
[lid
].ActiveWeapon
] == 0)
478 SwitchNextWeapon(g
,lid
);
480 if(g
->Lilanek
[lid
].ReloadTime
< g
->WeaponTemplate
[g
->Lilanek
[lid
].ActiveWeapon
].ReloadTime
){
481 g
->Lilanek
[lid
].ReloadTime
+= dtime
;
483 if(!g
->Lilanek
[lid
].WannaShoot
)
485 Shoot(g
, dtime
, lid
);
490 int UpdateLogic(Game
*g
,double dtime
){
491 DropWeapons(g
, dtime
);
492 UpdateBullets(g
, dtime
);
493 ParseInput(g
, dtime
);
494 MoveLilaneks(g
, dtime
);
495 PickUpWeapons(g
, dtime
);
496 ShootIfTheyWantTo(g
, dtime
);
497 return 0; //TODO: return something useful
500 Game
*testgame(){ //return testing game, function for use before we have some menu/loading mechanism
504 double sq2
= 1/sqrt(2.0);
506 Config conf
= GetConfig();
508 g
= malloc(sizeof(Game
));
509 g
->Map
= malloc(sizeof(TMap
));
511 g
->Map
->Layer
= malloc(sizeof(TMapLayer
*)*g
->Map
->noLayer
);
512 g
->Map
->Layer
[0] = malloc(sizeof(TMapLayer
));
513 g
->Map
->Layer
[0]->noFArea
= 1;
514 g
->Map
->Layer
[0]->FArea
= malloc(sizeof(Area
*) * g
->Map
->Layer
[0]->noFArea
);
515 p
= NewRect(4,2.5,3,2);
519 g
->Map
->Layer
[0]->FArea
[0] = a
;
521 g
->Map
->Layer
[1] = malloc(sizeof(TMapLayer
));
522 g
->Map
->Layer
[1]->noFArea
= 1;
523 g
->Map
->Layer
[1]->FArea
= malloc(sizeof(Area
*) * g
->Map
->Layer
[1]->noFArea
);
526 AddToPolyXY(p
, 11,9);
527 AddToPolyXY(p
, 9,11);
532 g
->Map
->Layer
[1]->FArea
[0] = a
;
533 p
= NewRect(1,1,16,15);
537 g
->Map
->BoundingArea
= a
;
543 g
->Map
->noSprites
= 2;
544 g
->Map
->Sprites
= (Sprite
**) malloc(sizeof(Sprite
*)*g
->Map
->noSprites
);
545 g
->Map
->SpritePos
= (Vect
*) malloc(sizeof(Vect
)*g
->Map
->noSprites
);
546 g
->Map
->SpritePos
[0].x
= 3.0;
547 g
->Map
->SpritePos
[0].y
= 1.0;
548 g
->Map
->SpritePos
[1].x
= 6.0;
549 g
->Map
->SpritePos
[1].y
= 6.0;
552 g
->Weapon
= malloc(sizeof(TWeapon
) * g
->noWeapons
);
554 fprintf(stderr
, "Cannot allocate memory for Weapons\n");
556 for(i
=0; i
<g
->noWeapons
; i
++){
557 g
->Weapon
[i
].Exists
= 0;
558 g
->Weapon
[i
].Shape
= 0;
562 g
->Lilanek
= malloc(sizeof(TLilanek
) * g
->noLilaneks
);
563 memset(g
->Lilanek
, 0, sizeof(TLilanek
) * g
->noLilaneks
);
564 g
->Lilanek
[1].Alive
= 0;
565 g
->Lilanek
[0].BSize
.x
= 1;
566 g
->Lilanek
[0].BSize
.y
= 1;
567 //g->Lilanek[0].Shape = NewRect(0.6,0.2,0.8,1.6);
569 AddToPolyXY(p
, 1, 0);
570 AddToPolyXY(p
, 1.4, 0.2);
571 AddToPolyXY(p
, 1.66, 1.38);
572 AddToPolyXY(p
, 1.42, 2);
573 AddToPolyXY(p
, 0.6, 2);
574 AddToPolyXY(p
, 0.4, 1.46);
575 AddToPolyXY(p
, 0.66, 0.2);
576 MultiplyPoly(p
, 0.5*g
->Lilanek
[0].BSize
.x
, 0.5*g
->Lilanek
[0].BSize
.y
);
580 g
->Lilanek
[0].Shape
= a
;
581 g
->Lilanek
[0].Pos
.x
= 12;
582 g
->Lilanek
[0].Pos
.y
= 4;
583 g
->Lilanek
[0].Speed
= 4;
584 g
->Lilanek
[0].Alive
= 0;
585 g
->Lilanek
[0].Keys
.Up
= conf
.pl1_key_up
;
586 g
->Lilanek
[0].Keys
.Down
= conf
.pl1_key_down
;
587 g
->Lilanek
[0].Keys
.Left
= conf
.pl1_key_left
;
588 g
->Lilanek
[0].Keys
.Right
= conf
.pl1_key_right
;
589 g
->Lilanek
[0].Keys
.Shoot
= conf
.pl1_key_fire
;
590 g
->Lilanek
[0].Keys
.Suicide
= conf
.pl1_key_suicide
;
591 g
->Lilanek
[0].Keys
.Switch
= conf
.pl1_key_switch
;
592 g
->Lilanek
[0].Ammo
= malloc(sizeof(int)*g
->noWID
);
593 for(i
=0; i
<g
->noWID
; i
++){
594 g
->Lilanek
[0].Ammo
[i
] = 0;
596 g
->Lilanek
[0].ActiveWeapon
= 0;
599 p
= g
->Lilanek
[0].Shape
->p
[0];
602 g
->Lilanek
[1].Shape
= a
;
603 g
->Lilanek
[1].BSize
.x
= g
->Lilanek
[0].BSize
.x
;
604 g
->Lilanek
[1].BSize
.y
= g
->Lilanek
[0].BSize
.y
;
605 g
->Lilanek
[1].Pos
.x
= 14;
606 g
->Lilanek
[1].Pos
.y
= 4;
607 g
->Lilanek
[1].Speed
= 4;
608 g
->Lilanek
[1].Alive
= 0;
609 g
->Lilanek
[1].Keys
.Up
= conf
.pl2_key_up
;
610 g
->Lilanek
[1].Keys
.Down
= conf
.pl2_key_down
;
611 g
->Lilanek
[1].Keys
.Left
= conf
.pl2_key_left
;
612 g
->Lilanek
[1].Keys
.Right
= conf
.pl2_key_right
;
613 g
->Lilanek
[1].Keys
.Shoot
= conf
.pl2_key_fire
;
614 g
->Lilanek
[1].Keys
.Suicide
= conf
.pl2_key_suicide
;
615 g
->Lilanek
[1].Keys
.Switch
= conf
.pl2_key_switch
;
616 g
->Lilanek
[1].Ammo
= malloc(sizeof(int)*g
->noWID
);
617 for(i
=0; i
<g
->noWID
; i
++){
618 g
->Lilanek
[1].Ammo
[i
] = 0;
620 g
->Lilanek
[1].ActiveWeapon
= 0;
624 g
->WeaponTemplate
= malloc(sizeof(TWeapon
)*g
->noWID
);
625 p
= NewRect(0,0,0.5,0.5);
629 g
->WeaponTemplate
[0].Shape
= a
;
630 g
->WeaponTemplate
[0].WID
= 0;
631 g
->WeaponTemplate
[0].Exists
= 1;
632 g
->WeaponTemplate
[0].Ammo
= 50;
633 g
->WeaponTemplate
[0].MaxAmmo
= 250;
634 g
->WeaponTemplate
[0].ReloadTime
= 2.1;
635 g
->WeaponTemplate
[0].Burst
= 10;
637 g
->BulletTemplate
= malloc(sizeof(TBullet
) * g
->noWID
);
638 p
= NewRect(0,0,0.1,0.1);
642 g
->BulletTemplate
[0].Shape
= a
;
643 g
->BulletTemplate
[0].WID
= 0;
644 g
->BulletTemplate
[0].Speed
= 20;
645 g
->BulletTemplate
[0].SFuzzy
= 0.040;
646 g
->BulletTemplate
[0].VFuzzy
= 0.000;
648 p
= NewRect(0,0,0.5,0.5);
652 g
->WeaponTemplate
[1].Shape
= a
;
653 g
->WeaponTemplate
[1].WID
= 1;
654 g
->WeaponTemplate
[1].Exists
= 1;
655 g
->WeaponTemplate
[1].Ammo
= 3;
656 g
->WeaponTemplate
[1].MaxAmmo
= 6;
657 g
->WeaponTemplate
[1].ReloadTime
= 0.5;
658 g
->WeaponTemplate
[1].Burst
= 1;
660 p
= NewRect(0,0,0.5,0.5);
664 g
->BulletTemplate
[1].Shape
= a
;
665 g
->BulletTemplate
[1].WID
= 1;
666 g
->BulletTemplate
[1].Speed
= 0;
667 g
->BulletTemplate
[1].SFuzzy
= 0.0;
668 g
->BulletTemplate
[1].VFuzzy
= 0.0;
671 g
->Bullet
= malloc(sizeof(TBullet
) * g
->noBullets
);
672 for(i
=0; i
<g
->noBullets
; i
++){
673 g
->Bullet
[i
].Exists
= 0;
674 g
->Bullet
[i
].Shape
= 0;
677 g
->PWeapondrop
= 0.4;
696 Uint32
callback_fps(Uint32 interval
, void *param
)
699 event
.type
= SDL_USEREVENT
;
700 SDL_PushEvent(&event
);
708 QueueDrawSprite(bg
, 0.0, 0.0,-1.0);
709 for(i
=0; i
< g
->Map
->noSprites
; i
++)
710 QueueDrawSprite(g
->Map
->Sprites
[i
], g
->Map
->SpritePos
[i
].x
, g
->Map
->SpritePos
[i
].y
, g
->Map
->Sprites
[i
]->z
);
712 QueueDrawSprite(lil
[g
->Lilanek
[0].Orientation
], g
->Lilanek
[0].Pos
.x
-1.0, g
->Lilanek
[0].Pos
.y
-1.0, 1);
713 QueueDrawSprite(lil
[g
->Lilanek
[1].Orientation
], g
->Lilanek
[1].Pos
.x
-1.0, g
->Lilanek
[1].Pos
.y
-1.0, 1);
715 for(i
=0; i
< g
->noWeapons
; i
++)
716 if(g
->Weapon
[i
].Exists
)
717 switch(g
->Weapon
[i
].WID
){
718 case 0: QueueDrawSprite(kul
, g
->Weapon
[i
].Pos
.x
- 1.0, g
->Weapon
[i
].Pos
.y
- 1.0,1.0); break;
719 case 1: QueueDrawSprite(mines
, g
->Weapon
[i
].Pos
.x
- 1.0, g
->Weapon
[i
].Pos
.y
- 1.0,1.0); break;
722 for(i
=0; i
< g
->noBullets
; i
++)
723 if(g
->Bullet
[i
].Exists
)
724 switch(g
->Bullet
[i
].WID
){
725 case 0: QueueDrawSprite(kulka
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
726 case 1: QueueDrawSprite(mine
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
731 int InitAll(Game
**g
){
735 //TODO: odstranit SaveConfig... je to tu jenom kvuli debugovani
738 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_TIMER
) < 0) {
739 fprintf(stderr
, "Unable to init SDL: %s\n", SDL_GetError());
747 lil
[0] = LoadSpriteSVG("graphics/lil.svg", 1.0, 1.0);
748 lil
[1] = LoadSpriteSVG("graphics/lilb.svg", 1.0, 1.0);
749 lil
[2] = LoadSpriteSVG("graphics/lill.svg", 1.0, 1.0);
750 lil
[3] = LoadSpriteSVG("graphics/lil.svg", 1.0, 1.0);
751 lil
[4] = LoadSpriteSVG("graphics/lilr.svg", 1.0, 1.0);
752 (*g
)->Map
->Sprites
[0] = LoadSpriteSVG("graphics/prek1.svg", 3.0, 3.0);
753 (*g
)->Map
->Sprites
[1] = LoadSpriteSVG("graphics/prek2.svg", 4.0, 4.0);
754 (*g
)->Map
->Sprites
[0]->z
= 1;
755 (*g
)->Map
->Sprites
[1]->z
= 1;
757 bg
= LoadSpriteSVG("graphics/bg.svg", 16.0, 15.0);
758 kul
= LoadSpriteSVG("graphics/kul.svg", 0.5, 0.5);
759 kulka
= LoadSpriteSVG("graphics/kulka.svg", 0.1, 0.1);
760 mine
= LoadSpriteSVG("graphics/mine.svg", 0.5, 0.5);
761 mines
= LoadSpriteSVG("graphics/mines.svg", 0.5, 0.5);
763 SDL_AddTimer(1000, callback_fps
, NULL
);
768 int GameLoop(Game
*g
){
771 double lasttime
, dtime
;
773 lasttime
= SDL_GetTicks()*0.001;
775 while (SDL_PollEvent(&event
)) {
776 switch (event
.type
) {
778 if (event
.key
.keysym
.sym
== SDLK_q
) {
787 case SDL_VIDEORESIZE
:
788 /* Resize the screen and redraw */
790 conf
.screen_width
=event
.resize
.w
;
791 conf
.screen_height
=event
.resize
.h
;
798 printf("%d frames\n",frames
);
806 dtime
= SDL_GetTicks()*0.001-lasttime
;
812 UpdateLogic(g
, dtime
*0.5);
813 UpdateLogic(g
, dtime
*0.5);
818 //we don't want to waste cpu...
826 int main(int argc
, char **argv
){