22 }TKeyBinding
;//TODO: s/int/real data type for a key
25 Vect Pos
; //where he is
26 Vect Move
; //how he want to move
27 Vect BSize
; //Size of bounding rect
28 Area
*Shape
; //how fat he is
29 //Area *TrShape; //translated Shape -- don't optimize yet
30 int Frags
; //no comment
32 double Speed
; //meters per second
33 int Orientation
; //1-up 2-left 3-down 4-right 0-down
34 int WannaShoot
; //1-want 0-don't want
35 double ReloadTime
; //time from last shot
36 int WannaDie
; //1-want suicide 2-died and still holding suicide 0-don't want
37 double AnimationTime
; //in seconds
52 int Exists
; // 0- doesn't exist 1-exists
62 Vect Vel
; //velocity i m/s
63 double Speed
; //for Templates
64 double Range
; //How far it can travel
66 int lid
; //who shoot this bullet?
67 int Exists
; // 0- doesn't exist 1-exists
68 double SFuzzy
; // Fuzzy factor for spawning 0-1 :)
69 double VFuzzy
; // Fuzzy factor for traveling 0-1 :)
74 TMap
*Map
; //where we are playing
75 TLilanek
*Lilanek
; //our heroes-ehm bad guys
78 TWeapon
*Weapon
; //Weapons lying on floor
80 TWeapon
*WeaponTemplate
;
81 TBullet
*BulletTemplate
;
82 int noWID
; //biggest WID, also number of WeaponTemplates
85 double PWeapondrop
; // Probability of weapon drop per second
113 void SwitchNextWeapon(Game
*g
, int lid
);
119 Orientations
[1].y
=-1;
120 Orientations
[2].x
=-1;
131 void SpawnLilanek(Game
*g
, int lid
){
140 for(tries
=0; tries
<1000; tries
++){ //TODO: remove exact number
141 Pos
.x
= RandD(0,g
->Map
->XX
);
142 Pos
.y
= RandD(0,g
->Map
->YY
);
144 tp
= TranslateArea(g
->Lilanek
[lid
].Shape
, &Pos
);
145 printf("%s\n", Area2String(tp
));
146 if(!AreaInMap(g
->Map
, tp
,0,1)){
150 for(olid
=0; olid
< g
->noLilaneks
; olid
++){
153 if(!g
->Lilanek
[olid
].Alive
){
156 oltp
= TranslateArea(g
->Lilanek
[olid
].Shape
, &g
->Lilanek
[olid
].Pos
);
157 if(AreaInArea(tp
, oltp
)){
167 g
->Lilanek
[lid
].Pos
.x
= Pos
.x
;
168 g
->Lilanek
[lid
].Pos
.y
= Pos
.y
;
169 g
->Lilanek
[lid
].Alive
= 1;
177 void DropWeapon(Game
*g
, int weapon
){
183 for(tries
=0; tries
<100; tries
++){ //TODO: remove exact number
184 Pos
.x
= RandD(0,g
->Map
->XX
);
185 Pos
.y
= RandD(0,g
->Map
->YY
);
186 WID
= RandI(0, g
->noWID
);
187 tp
= TranslateArea(g
->WeaponTemplate
[WID
].Shape
, &Pos
);
188 if(AreaInMap(g
->Map
, tp
, 0, g
->Map
->noLayer
)){
191 memcpy(&g
->Weapon
[weapon
], &g
->WeaponTemplate
[WID
], sizeof(TWeapon
));
192 g
->Weapon
[weapon
].Shape
= g
->WeaponTemplate
[WID
].Shape
;
193 g
->Weapon
[weapon
].Pos
.x
= Pos
.x
;
194 g
->Weapon
[weapon
].Pos
.y
= Pos
.y
;
195 g
->Weapon
[weapon
].WID
= WID
;
196 g
->Weapon
[weapon
].Exists
= 1;
204 void DropWeapons(Game
*g
, double dtime
){
207 if( RandD(0.0, 1.0) >= (g
->PWeapondrop
*dtime
))
209 for(i
=0; i
< g
->noWeapons
; i
++){
210 if(g
->Weapon
[i
].Exists
)continue; //we don't like teleporting weapons :)
212 printf("A Weapon drop!\n");
214 break; //spawn max one weapon per update
218 void WeaponPickedUp(Game
*g
, double dtime
, int lid
, int wid
){
222 l
= &g
->Lilanek
[lid
];
225 l
->Ammo
[w
->WID
] += w
->Ammo
;
226 if(l
->Ammo
[w
->WID
] > w
->MaxAmmo
)
227 l
->Ammo
[w
->WID
] = w
->MaxAmmo
;
228 printf("Ammo: %d\n",l
->Ammo
[w
->WID
]);
229 l
->ActiveWeapon
= w
->WID
;
230 printf("AW: %d\n",l
->ActiveWeapon
);
237 void PickUpWeapons(Game
*g
, double dtime
){
241 for(lid
=0; lid
<g
->noLilaneks
; lid
++){
242 LArea
= TranslateArea(g
->Lilanek
[lid
].Shape
, &g
->Lilanek
[lid
].Pos
);
243 for(wid
=0; wid
< g
->noWeapons
; wid
++){
244 if(!g
->Weapon
[wid
].Exists
)
246 WArea
= TranslateArea(g
->Weapon
[wid
].Shape
, &g
->Weapon
[wid
].Pos
);
247 if(!AreaInArea( WArea
, LArea
)){
251 WeaponPickedUp(g
, dtime
, lid
, wid
);
258 void BulletExplodes(Game
*g
, int i
){
259 g
->Bullet
[i
].Exists
=0;
263 void MoveBullet(Game
*g
, double dtime
, int i
){
266 dp
.x
= g
->Bullet
[i
].Pos
.x
;
267 dp
.y
= g
->Bullet
[i
].Pos
.y
;
268 ff
= g
->Bullet
[i
].Speed
*g
->Bullet
[i
].VFuzzy
;
269 g
->Bullet
[i
].Pos
.x
+= (g
->Bullet
[i
].Vel
.x
+= RandD(-ff
,ff
))* dtime
;
270 g
->Bullet
[i
].Pos
.y
+= (g
->Bullet
[i
].Vel
.y
+= RandD(-ff
,ff
))* dtime
;
271 dp
.x
-= g
->Bullet
[i
].Pos
.x
;
272 dp
.y
-= g
->Bullet
[i
].Pos
.y
;
273 g
->Bullet
[i
].Range
-= sqrt(DotProduct(&dp
, &dp
));
276 void CollideBulletMap(Game
*g
, double dtime
, int i
){
279 p
=TranslateArea(g
->Bullet
[i
].Shape
, &g
->Bullet
[i
].Pos
);
280 if(AreaInMap(g
->Map
, p
, 1,1)==0)
281 BulletExplodes(g
, i
);
285 void BloodColorFunc(double temp
, SDL_Color
*c
)
287 SDL_Color col
={255,255,255,255};
288 col
.r
*=(0.5+0.5*temp
);
291 //col.unused *=temp*temp;
292 if (c
!= 0) memcpy(c
, &col
, sizeof(SDL_Color
));
295 void BloodParticles(Game
*g
, double dtime
, int lid
)
302 for(i
= 0; i
< 5; i
++){
303 p
= malloc(sizeof(Particle
));
304 memset(p
, 0, sizeof(Particle
));
305 a
= RandD(0.0, 20.0);
307 p
->x
= g
->Lilanek
[lid
].Pos
.x
-g
->Lilanek
[lid
].BSize
.x
*0.5;
308 p
->y
= g
->Lilanek
[lid
].Pos
.y
-g
->Lilanek
[lid
].BSize
.y
*0.5;
316 p
->tf
= &BloodColorFunc
;
322 void LilanekKilled(Game
*g
, double dtime
, int BulletID
, int LilanekID
){
324 g
->Bullet
[BulletID
].Exists
= 0;
325 g
->Lilanek
[LilanekID
].Deaths
++;
326 g
->Lilanek
[g
->Bullet
[BulletID
].lid
].Frags
++;
327 BloodParticles(g
, dtime
, LilanekID
);
328 SpawnLilanek(g
, LilanekID
);
329 for(i
=0; i
<g
->noWID
; i
++){
330 g
->Lilanek
[LilanekID
].Ammo
[i
] = 0;
335 #define NO_EXPLOSIONS 10 //MAGIC_NUMBER
336 #define EXPLOSION_SPEED 5 //MAGIC_NUMBER
337 #define EXPLOSION_RANGE 1.0 //MAGIC_NUMBER
339 void SpawnExplosions(Game
*g
, double dtime
, int BulletID
){
346 Pos
.x
= g
->Bullet
[BulletID
].Pos
.x
;
347 Pos
.y
= g
->Bullet
[BulletID
].Pos
.y
;
348 for(i
=0; i
<NO_EXPLOSIONS
; i
++){
349 for(bid
=0; bid
<g
->noBullets
; bid
++){
350 if(g
->Bullet
[bid
].Exists
)
355 b
->Vel
.x
= RandD(0.0, 1.0)*(RandI(0,100)>50?-1:1);
356 b
->Vel
.y
= RandD(0.0, 1.0)*(RandI(0,100)>50?-1:1);
358 speed
= RandD(0.3, 1.0)*EXPLOSION_SPEED
;
363 b
->lid
= g
->Bullet
[BulletID
].lid
;
367 b
->Range
= EXPLOSION_RANGE
;
368 b
->Shape
= g
->Bullet
[BulletID
].Shape
;
369 printf("%lf ", speed
);
373 g
->Bullet
[BulletID
].Exists
= 0;
377 void CollideBulletLilanek(Game
*g
, double dtime
, int BulletID
){
381 BArea
=TranslateArea(g
->Bullet
[BulletID
].Shape
, &g
->Bullet
[BulletID
].Pos
);
382 for(LilanekID
=0; LilanekID
<g
->noLilaneks
; LilanekID
++){
383 LArea
=TranslateArea(g
->Lilanek
[LilanekID
].Shape
, &g
->Lilanek
[LilanekID
].Pos
);
384 if(AreaInArea(LArea
,BArea
)){
385 //if it is a mine, spawn explosion instead of killing instantly
386 if(g
->Bullet
[BulletID
].WID
== 1){
387 SpawnExplosions(g
, dtime
, BulletID
);
389 LilanekKilled(g
, dtime
, BulletID
, LilanekID
);
399 void UpdateBullets(Game
*g
, double dtime
){
401 for(BulletID
=0; BulletID
<g
->noBullets
; BulletID
++){
402 if(g
->Bullet
[BulletID
].Exists
==0)
403 continue; //We won't update non-existending bullets
404 MoveBullet(g
, dtime
, BulletID
);
405 if(g
->Bullet
[BulletID
].Range
< 0){
406 g
->Bullet
[BulletID
].Exists
= 0;
409 CollideBulletMap(g
, dtime
, BulletID
);
410 CollideBulletLilanek(g
, dtime
, BulletID
);
414 int CheckLilanekvsLilaneks(Game
*g
, Area
*a
, int LilanekID
){ //returns 0 if he collides with others, 1 if it's OK to move there
420 for(i
=0; i
<g
->noLilaneks
&& rval
==1; i
++){
423 nb
= TranslateArea(g
->Lilanek
[i
].Shape
, &g
->Lilanek
[i
].Pos
);
424 if(AreaInArea(nb
, a
))
432 void MoveLilaneks(Game
*g
, double dtime
){
439 for(i
=0; i
<g
->noLilaneks
; i
++){
440 //skip this Lilanek if he doesn't wanna move
441 if(g
->Lilanek
[i
].Move
.x
== 0.0 && g
->Lilanek
[i
].Move
.y
== 0.0)
443 for(dt
=dtime
, steps
=0; steps
<4; dt
/=2.0, steps
++){ //TODO: get rid of exact number
445 va
.x
= g
->Lilanek
[i
].Pos
.x
+ dt
*g
->Lilanek
[i
].Move
.x
;
446 va
.y
= g
->Lilanek
[i
].Pos
.y
+ dt
*g
->Lilanek
[i
].Move
.y
;
447 FreeArea(pa
); //we don't want memory leaks
448 pa
= TranslateArea(g
->Lilanek
[i
].Shape
, &va
);
449 //check for collision with map
450 if(AreaInMap(g
->Map
, pa
, 0, 1)==0)
451 continue; //try smaller dt if he collided with map
452 //check for collision with other Lilaneks
453 if(CheckLilanekvsLilaneks(g
, pa
, i
)==0)
455 //move him if we got here
456 g
->Lilanek
[i
].Pos
.x
+= dt
*g
->Lilanek
[i
].Move
.x
;
457 g
->Lilanek
[i
].Pos
.y
+= dt
*g
->Lilanek
[i
].Move
.y
;
461 FreeArea(pa
); //For sure
466 void ParseInput(Game
*g
, double dtime
){
472 keystate
= SDL_GetKeyState(NULL
);
485 for(i
=0; i
< g
->noLilaneks
; i
++){
486 curlil
= &g
->Lilanek
[i
];
489 if(keystate
[curlil
->Keys
.Up
]){
490 curlil
->Orientation
= 1;
491 curlil
->Move
.x
= curlil
->Speed
* Orientations
[1].x
;
492 curlil
->Move
.y
= curlil
->Speed
* Orientations
[1].y
;
496 if(keystate
[curlil
->Keys
.Down
]){
497 curlil
->Orientation
= 3;
498 curlil
->Move
.x
= curlil
->Speed
* Orientations
[3].x
;
499 curlil
->Move
.y
= curlil
->Speed
* Orientations
[3].y
;
503 if(keystate
[curlil
->Keys
.Left
]){
504 curlil
->Orientation
= 2;
505 curlil
->Move
.x
= curlil
->Speed
* Orientations
[2].x
;
506 curlil
->Move
.y
= curlil
->Speed
* Orientations
[2].y
;
510 if(keystate
[curlil
->Keys
.Right
]){
511 curlil
->Orientation
= 4;
512 curlil
->Move
.x
= curlil
->Speed
* Orientations
[4].x
;
513 curlil
->Move
.y
= curlil
->Speed
* Orientations
[4].y
;
522 if(keystate
[curlil
->Keys
.Shoot
]){
523 curlil
->WannaShoot
= 1;
525 curlil
->WannaShoot
= 0;
528 if(keystate
[curlil
->Keys
.Suicide
]){
529 if(curlil
->WannaDie
!= 2){
530 curlil
->WannaDie
= 1;
533 curlil
->WannaDie
= 0;
536 if(keystate
[curlil
->Keys
.Switch
]){
537 if(!curlil
->SwitchLock
){
538 SwitchNextWeapon(g
, i
);
539 curlil
->SwitchLock
= 1;
542 curlil
->SwitchLock
= 0;
547 void SpawnBullet(Game
*g
, double dtime
, int lid
, int bid
){
550 double vx
, vy
; //because we need to spawn also mines with no velocity
553 LArea
= TranslateArea(g
->Lilanek
[lid
].Shape
, &g
->Lilanek
[lid
]. Pos
);
555 bt
= &g
->BulletTemplate
[g
->Lilanek
[lid
].ActiveWeapon
];
556 memcpy (b
, bt
, sizeof(TBullet
));
558 b
->Pos
.x
= g
->Lilanek
[lid
].Pos
.x
+g
->Lilanek
[lid
].BSize
.x
*0.5;
559 b
->Pos
.y
= g
->Lilanek
[lid
].Pos
.y
+g
->Lilanek
[lid
].BSize
.y
*0.5;
561 b
->Range
= bt
->Range
;
562 b
->Vel
.x
= Orientations
[g
->Lilanek
[lid
].Orientation
].x
* b
->Speed
+RandD(-b
->Speed
*b
->SFuzzy
, b
->Speed
*b
->SFuzzy
);
563 b
->Vel
.y
= Orientations
[g
->Lilanek
[lid
].Orientation
].y
* b
->Speed
+RandD(-b
->Speed
*b
->SFuzzy
, b
->Speed
*b
->SFuzzy
);
564 if(DotProduct(&b
->Vel
, &b
->Vel
) <=0.01){
565 vx
= -1*Orientations
[g
->Lilanek
[lid
].Orientation
].x
;
566 vy
= -1*Orientations
[g
->Lilanek
[lid
].Orientation
].y
;
573 BArea
= TranslateArea(b
->Shape
, &b
->Pos
);
574 if(!AreaInArea(BArea
, LArea
))
576 b
->Pos
.x
+= vx
* dtime
*0.5;
577 b
->Pos
.y
+= vy
* dtime
*0.5;
582 void DustColorFunc(double temp
, SDL_Color
*c
)
584 SDL_Color col
={255,255,255,255};
588 col
.unused
*=temp
*temp
;
589 if (c
!= 0) memcpy(c
, &col
, sizeof(SDL_Color
));
592 void ShootParticles(Game
*g
, double dtime
, int lid
)
599 for(i
= 1; i
< 10; i
++){
600 p
= malloc(sizeof(Particle
));
601 memset(p
, 0, sizeof(Particle
));
602 a
= RandD(0.0, 2*M_PI
);
604 p
->x
= g
->Lilanek
[lid
].Pos
.x
-g
->Lilanek
[lid
].BSize
.x
*0.5;
605 p
->y
= g
->Lilanek
[lid
].Pos
.y
-g
->Lilanek
[lid
].BSize
.y
*0.5;
612 p
->tf
= &DustColorFunc
;
617 void Shoot(Game
*g
, double dtime
, int lid
){
621 for(i
=0; i
<g
->WeaponTemplate
[g
->Lilanek
[lid
].ActiveWeapon
].Burst
; i
++){
622 if(g
->Lilanek
[lid
].Ammo
[g
->Lilanek
[lid
].ActiveWeapon
] == 0)
624 for(bid
=0; bid
<g
->noBullets
; bid
++){
625 if(g
->Bullet
[bid
].Exists
)
627 SpawnBullet(g
, dtime
, lid
, bid
);
628 g
->Lilanek
[lid
].Ammo
[g
->Lilanek
[lid
].ActiveWeapon
]--;
629 g
->Lilanek
[lid
].ReloadTime
= 0;
633 ShootParticles(g
, dtime
, lid
);
634 switch(g
->Lilanek
[lid
].ActiveWeapon
){
635 case 0: PlaySound(s_shoot
); break;
636 case 1: PlaySound(s_mine
); break;
637 case 2: PlaySound(s_shoot
); break;
642 void SwitchNextWeapon(Game
*g
, int lid
){
645 l
= &g
->Lilanek
[lid
];
646 for(i
= 1; i
< g
->noWID
; i
++){
647 if(l
->Ammo
[(l
->ActiveWeapon
+i
)%(g
->noWID
)]){
648 l
->ActiveWeapon
= (l
->ActiveWeapon
+i
)%(g
->noWID
);
654 void ShootIfTheyWantTo(Game
*g
, double dtime
){
657 for(lid
=0; lid
<g
->noLilaneks
; lid
++){
658 //if(!g->Lilanek[lid].Exists)
660 if(g
->Lilanek
[lid
].Ammo
[g
->Lilanek
[lid
].ActiveWeapon
] == 0)
661 SwitchNextWeapon(g
,lid
);
663 if(g
->Lilanek
[lid
].ReloadTime
< g
->WeaponTemplate
[g
->Lilanek
[lid
].ActiveWeapon
].ReloadTime
){
664 g
->Lilanek
[lid
].ReloadTime
+= dtime
;
666 if(!g
->Lilanek
[lid
].WannaShoot
)
668 Shoot(g
, dtime
, lid
);
673 int UpdateLogic(Game
*g
,double dtime
){
675 DropWeapons(g
, dtime
);
676 UpdateBullets(g
, dtime
);
678 ParseInput(g
, dtime
);
680 MoveLilaneks(g
, dtime
);
681 PickUpWeapons(g
, dtime
);
682 ShootIfTheyWantTo(g
, dtime
);
684 return 0; //TODO: return something useful
687 Game
*testgame(){ //return testing game, function for use before we have some menu/loading mechanism
692 Config conf
= GetConfig();
694 g
= malloc(sizeof(Game
));
695 memset(g
, 0, sizeof(Game
));
697 g
->Map
= malloc(sizeof(TMap
));
699 g
->Map
->Layer
= malloc(sizeof(TMapLayer
*)*g
->Map
->noLayer
);
700 g
->Map
->Layer
[0] = malloc(sizeof(TMapLayer
));
701 g
->Map
->Layer
[0]->noFArea
= 1;
702 g
->Map
->Layer
[0]->FArea
= malloc(sizeof(Area
*) * g
->Map
->Layer
[0]->noFArea
);
703 p
= NewRect(4,2.5,3,2);
707 g
->Map
->Layer
[0]->FArea
[0] = a
;
709 g
->Map
->Layer
[1] = malloc(sizeof(TMapLayer
));
710 g
->Map
->Layer
[1]->noFArea
= 1;
711 g
->Map
->Layer
[1]->FArea
= malloc(sizeof(Area
*) * g
->Map
->Layer
[1]->noFArea
);
713 AddToPolyXY(p
, 0.30, 0.41);
714 AddToPolyXY(p
, 0.73, 0.41);
715 AddToPolyXY(p
, 0.77, 0.79);
716 AddToPolyXY(p
, 0.65, 0.955);
717 AddToPolyXY(p
, 0.365, 0.965);
718 AddToPolyXY(p
, 0.235, 0.785);
719 MultiplyPoly(p
, 4, 4);
720 pp
= TranslatePolyXY(p
, 7, 7);
725 g
->Map
->Layer
[1]->FArea
[0] = a
;
726 p
= NewRect(1,1,16,15);
730 g
->Map
->BoundingArea
= a
;
736 g
->Map
->noSprites
= 2;
737 g
->Map
->Sprites
= (Sprite
**) malloc(sizeof(Sprite
*)*g
->Map
->noSprites
);
738 g
->Map
->SpritePos
= (Vect
*) malloc(sizeof(Vect
)*g
->Map
->noSprites
);
739 g
->Map
->SpritePos
[0].x
= 3.0;
740 g
->Map
->SpritePos
[0].y
= 1.0;
741 g
->Map
->SpritePos
[1].x
= 6.0;
742 g
->Map
->SpritePos
[1].y
= 6.0;
745 g
->Weapon
= malloc(sizeof(TWeapon
) * g
->noWeapons
);
747 fprintf(stderr
, "Cannot allocate memory for Weapons\n");
749 for(i
=0; i
<g
->noWeapons
; i
++){
750 g
->Weapon
[i
].Exists
= 0;
751 g
->Weapon
[i
].Shape
= 0;
755 g
->Lilanek
= malloc(sizeof(TLilanek
) * g
->noLilaneks
);
756 memset(g
->Lilanek
, 0, sizeof(TLilanek
) * g
->noLilaneks
);
757 g
->Lilanek
[0].BSize
.x
= 1;
758 g
->Lilanek
[0].BSize
.y
= 1;
759 //g->Lilanek[0].Shape = NewRect(0.6,0.2,0.8,1.6);
761 AddToPolyXY(p
, 1, 0);
762 AddToPolyXY(p
, 1.4, 0.2);
763 AddToPolyXY(p
, 1.66, 1.38);
764 AddToPolyXY(p
, 1.42, 2);
765 AddToPolyXY(p
, 0.6, 2);
766 AddToPolyXY(p
, 0.4, 1.46);
767 AddToPolyXY(p
, 0.66, 0.2);
768 MultiplyPoly(p
, 0.5*g
->Lilanek
[0].BSize
.x
, 0.5*g
->Lilanek
[0].BSize
.y
);
772 g
->Lilanek
[0].Shape
= a
;
773 g
->Lilanek
[0].Pos
.x
= 12;
774 g
->Lilanek
[0].Pos
.y
= 4;
775 g
->Lilanek
[0].Speed
= 4;
776 g
->Lilanek
[0].Alive
= 0;
777 g
->Lilanek
[0].Keys
.Up
= conf
.pl1_key_up
;
778 g
->Lilanek
[0].Keys
.Down
= conf
.pl1_key_down
;
779 g
->Lilanek
[0].Keys
.Left
= conf
.pl1_key_left
;
780 g
->Lilanek
[0].Keys
.Right
= conf
.pl1_key_right
;
781 g
->Lilanek
[0].Keys
.Shoot
= conf
.pl1_key_fire
;
782 g
->Lilanek
[0].Keys
.Suicide
= conf
.pl1_key_suicide
;
783 g
->Lilanek
[0].Keys
.Switch
= conf
.pl1_key_switch
;
784 g
->Lilanek
[0].Ammo
= malloc(sizeof(int)*g
->noWID
);
785 for(i
=0; i
<g
->noWID
; i
++){
786 g
->Lilanek
[0].Ammo
[i
] = 0;
788 g
->Lilanek
[0].ActiveWeapon
= 0;
790 SDL_Color red
= {255,211,211,255};
792 g
->Lilanek
[0].Color
= red
;
793 strcpy(g
->Lilanek
[0].Name
, redn
);
795 g
->Lilanek
[1].Alive
= 0; // little hack for SpawnLilanek to work
798 p
= g
->Lilanek
[0].Shape
->p
[0];
801 g
->Lilanek
[1].Shape
= a
;
802 g
->Lilanek
[1].BSize
.x
= g
->Lilanek
[0].BSize
.x
;
803 g
->Lilanek
[1].BSize
.y
= g
->Lilanek
[0].BSize
.y
;
804 g
->Lilanek
[1].Pos
.x
= 14;
805 g
->Lilanek
[1].Pos
.y
= 4;
806 g
->Lilanek
[1].Speed
= 4;
807 g
->Lilanek
[1].Alive
= 0;
808 g
->Lilanek
[1].Keys
.Up
= conf
.pl2_key_up
;
809 g
->Lilanek
[1].Keys
.Down
= conf
.pl2_key_down
;
810 g
->Lilanek
[1].Keys
.Left
= conf
.pl2_key_left
;
811 g
->Lilanek
[1].Keys
.Right
= conf
.pl2_key_right
;
812 g
->Lilanek
[1].Keys
.Shoot
= conf
.pl2_key_fire
;
813 g
->Lilanek
[1].Keys
.Suicide
= conf
.pl2_key_suicide
;
814 g
->Lilanek
[1].Keys
.Switch
= conf
.pl2_key_switch
;
815 g
->Lilanek
[1].Ammo
= malloc(sizeof(int)*g
->noWID
);
816 for(i
=0; i
<g
->noWID
; i
++){
817 g
->Lilanek
[1].Ammo
[i
] = 0;
819 g
->Lilanek
[1].ActiveWeapon
= 0;
821 SDL_Color blue
= {180,180,255, 255};
822 char bluen
[8]="Blue";
823 g
->Lilanek
[1].Color
= blue
;
824 strcpy(g
->Lilanek
[1].Name
, bluen
);
828 g
->WeaponTemplate
= malloc(sizeof(TWeapon
)*g
->noWID
);
829 p
= NewRect(0,0,0.5,0.5);
833 g
->WeaponTemplate
[0].Shape
= a
;
834 g
->WeaponTemplate
[0].WID
= 0;
835 g
->WeaponTemplate
[0].Exists
= 1;
836 g
->WeaponTemplate
[0].Ammo
= 30;
837 g
->WeaponTemplate
[0].MaxAmmo
= 120;
838 g
->WeaponTemplate
[0].ReloadTime
= 0.7;
839 g
->WeaponTemplate
[0].Burst
= 10;
841 g
->BulletTemplate
= malloc(sizeof(TBullet
) * g
->noWID
);
842 p
= NewRect(0,0,0.1,0.1);
846 g
->BulletTemplate
[0].Shape
= a
;
847 g
->BulletTemplate
[0].WID
= 0;
848 g
->BulletTemplate
[0].Speed
= 20;
849 g
->BulletTemplate
[0].Range
= 20;
850 g
->BulletTemplate
[0].SFuzzy
= 0.160;
851 g
->BulletTemplate
[0].VFuzzy
= 0.000;
853 p
= NewRect(0,0,0.5,0.5);
857 g
->WeaponTemplate
[1].Shape
= a
;
858 g
->WeaponTemplate
[1].WID
= 1;
859 g
->WeaponTemplate
[1].Exists
= 1;
860 g
->WeaponTemplate
[1].Ammo
= 3;
861 g
->WeaponTemplate
[1].MaxAmmo
= 6;
862 g
->WeaponTemplate
[1].ReloadTime
= 0.5;
863 g
->WeaponTemplate
[1].Burst
= 1;
865 p
= NewRect(0,0,0.5,0.5);
869 g
->BulletTemplate
[1].Shape
= a
;
870 g
->BulletTemplate
[1].WID
= 1;
871 g
->BulletTemplate
[1].Speed
= 0;
872 g
->BulletTemplate
[1].Range
= 20;
873 g
->BulletTemplate
[1].SFuzzy
= 0.0;
874 g
->BulletTemplate
[1].VFuzzy
= 0.0;
876 p
= NewRect(0,0,0.5,0.5);
880 g
->WeaponTemplate
[2].Shape
= a
;
881 g
->WeaponTemplate
[2].WID
= 0;
882 g
->WeaponTemplate
[2].Exists
= 1;
883 g
->WeaponTemplate
[2].Ammo
= 10;
884 g
->WeaponTemplate
[2].MaxAmmo
= 50;
885 g
->WeaponTemplate
[2].ReloadTime
= 0.1;
886 g
->WeaponTemplate
[2].Burst
= 1;
888 p
= NewRect(0,0,0.1,0.1);
892 g
->BulletTemplate
[2].Shape
= a
;
893 g
->BulletTemplate
[2].WID
= 0;
894 g
->BulletTemplate
[2].Speed
= 20;
895 g
->BulletTemplate
[2].Range
= 20;
896 g
->BulletTemplate
[2].SFuzzy
= 0.040;
897 g
->BulletTemplate
[2].VFuzzy
= 0.010;
899 g
->Bullet
= malloc(sizeof(TBullet
) * g
->noBullets
);
900 for(i
=0; i
<g
->noBullets
; i
++){
901 g
->Bullet
[i
].Exists
= 0;
902 g
->Bullet
[i
].Shape
= 0;
905 g
->PWeapondrop
= 0.4;
917 Uint32
callback_fps(Uint32 interval
, void *param
)
920 event
.type
= SDL_USEREVENT
;
921 SDL_PushEvent(&event
);
929 QueueDrawSprite(bg
, 0.0, 0.0,-1.0);
930 for(i
=0; i
< g
->Map
->noSprites
; i
++)
931 QueueDrawSprite(g
->Map
->Sprites
[i
], g
->Map
->SpritePos
[i
].x
, g
->Map
->SpritePos
[i
].y
, g
->Map
->Sprites
[i
]->z
);
933 for(i
=0; i
< g
->noLilaneks
; i
++){
936 c
=g
->Lilanek
[i
].Color
;
937 if(g
->Lilanek
[i
].ReloadTime
< g
->WeaponTemplate
[g
->Lilanek
[i
].ActiveWeapon
].ReloadTime
){
943 QueueDrawSpriteColorize(lil
[g
->Lilanek
[i
].Orientation
], g
->Lilanek
[i
].Pos
.x
-1.0, g
->Lilanek
[i
].Pos
.y
-1.0, 1, c
);
944 QueueDrawSpriteColorize(hud
,16.0,4.0*i
, 1.0, c
);
945 switch(g
->Lilanek
[i
].ActiveWeapon
){
946 case 0: QueueDrawSprite(hud_brok
, 16.0, 0.0+4.0*i
,0.0);
948 case 1: QueueDrawSprite(hud_mine
, 16.0, 0.0+4.0*i
,0.0);
950 case 2: QueueDrawSprite(hud_kul
, 16.0, 0.0+4.0*i
,0.0);
953 pd
= (double)g
->Lilanek
[i
].Ammo
[g
->Lilanek
[i
].ActiveWeapon
]/(double)g
->WeaponTemplate
[g
->Lilanek
[i
].ActiveWeapon
].MaxAmmo
;
954 QueueDrawSpriteColorizeStretch(hud_ammo
, 18.0-2.0*pd
, 0.0+4.0*i
,4.0*pd
, 4.0, 2.0,c
);
955 pd
= (double)g
->Lilanek
[i
].ReloadTime
/(double)g
->WeaponTemplate
[g
->Lilanek
[i
].ActiveWeapon
].ReloadTime
;
957 QueueDrawSpriteColorizeStretch(hud_reload
, 18.0-2.0*pd
, 0.0+4.0*i
,4.0*pd
, 4.0, 2.0,c
);
960 for(i
=0; i
< g
->noWeapons
; i
++)
961 if(g
->Weapon
[i
].Exists
)
962 switch(g
->Weapon
[i
].WID
){
963 case 0: QueueDrawSprite(brok
, g
->Weapon
[i
].Pos
.x
- 1.0, g
->Weapon
[i
].Pos
.y
- 1.0,1.0);
965 case 1: QueueDrawSprite(mines
, g
->Weapon
[i
].Pos
.x
- 1.0, g
->Weapon
[i
].Pos
.y
- 1.0,1.0);
967 case 2: QueueDrawSprite(kul
, g
->Weapon
[i
].Pos
.x
- 1.0, g
->Weapon
[i
].Pos
.y
- 1.0,1.0);
971 for(i
=0; i
< g
->noBullets
; i
++)
972 if(g
->Bullet
[i
].Exists
)
973 switch(g
->Bullet
[i
].WID
){
974 case 0: QueueDrawSprite(kulka
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
975 case 1: QueueDrawSprite(mine
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
976 case 2: QueueDrawSprite(kulka
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
977 case -1: QueueDrawSprite(explo
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
982 int InitAll(Game
**g
){
986 //TODO: odstranit SaveConfig... je to tu jenom kvuli debugovani
989 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_TIMER
|SDL_INIT_AUDIO
) < 0) {
990 fprintf(stderr
, "Unable to init SDL: %s\n", SDL_GetError());
999 lil
[0] = LoadSpriteSVG("graphics/lil.svg", 1.0, 1.0);
1000 lil
[1] = LoadSpriteSVG("graphics/lilb.svg", 1.0, 1.0);
1001 lil
[2] = LoadSpriteSVG("graphics/lill.svg", 1.0, 1.0);
1002 lil
[3] = LoadSpriteSVG("graphics/lil.svg", 1.0, 1.0);
1003 lil
[4] = LoadSpriteSVG("graphics/lilr.svg", 1.0, 1.0);
1004 (*g
)->Map
->Sprites
[0] = LoadSpriteSVG("graphics/prek1.svg", 3.0, 3.0);
1005 (*g
)->Map
->Sprites
[1] = LoadSpriteSVG("graphics/prek2.svg", 4.0, 4.0);
1006 (*g
)->Map
->Sprites
[0]->z
= 1;
1007 (*g
)->Map
->Sprites
[1]->z
= 1;
1009 bg
= LoadSpriteSVG("graphics/bg.svg", 16.0, 15.0);
1010 kul
= LoadSpriteSVG("graphics/kul.svg", 0.5, 0.5);
1011 explo
= LoadSpriteSVG("graphics/exp.svg", 0.5, 0.5);
1012 dust
= LoadSpriteSVG("graphics/dust.svg", 0.5, 0.5);
1013 blood
= LoadSpriteSVG("graphics/blood.svg", 0.5, 0.5);
1014 brok
= LoadSpriteSVG("graphics/brok.svg", 0.5, 0.5);
1015 kulka
= LoadSpriteSVG("graphics/kulka.svg", 0.1, 0.1);
1016 mine
= LoadSpriteSVG("graphics/mine.svg", 0.5, 0.5);
1017 mines
= LoadSpriteSVG("graphics/mines.svg", 0.5, 0.5);
1018 hud
= LoadSpriteSVG("graphics/hud.svg", 4.0, 4.0);
1019 hud_mine
= LoadSpriteSVG("graphics/mines.svg", 2.2, 2.2);
1020 hud_kul
= LoadSpriteSVG("graphics/kul.svg", 2.2, 2.2);
1021 hud_brok
= LoadSpriteSVG("graphics/brok.svg", 2.2, 2.2);
1022 hud_ammo
= LoadSpriteSVG("graphics/hud_ammo.svg", 4.0, 4.0);
1023 hud_reload
= LoadSpriteSVG("graphics/hud_reload.svg", 4.0, 4.0);
1025 s_die
= LoadSound("sounds/die.wav");
1026 s_bonus
= LoadSound("sounds/bonus.wav");
1027 s_expl
= LoadSound("sounds/expl.wav");
1028 s_shoot
= LoadSound("sounds/shoot.wav");
1029 s_mine
= LoadSound("sounds/mine.wav");
1031 SDL_AddTimer(1000, callback_fps
, NULL
);
1036 int GameLoop(Game
*g
){
1039 double lasttime
, dtime
;
1041 lasttime
= SDL_GetTicks()*0.001;
1043 while (SDL_PollEvent(&event
)) {
1044 switch (event
.type
) {
1046 if (event
.key
.keysym
.sym
== SDLK_q
) {
1055 case SDL_VIDEORESIZE
:
1056 /* Resize the screen and redraw */
1058 conf
.screen_width
=event
.resize
.w
;
1059 conf
.screen_height
=event
.resize
.h
;
1062 InvalidateSprites();
1066 printf("%d frames\n",frames
);
1074 dtime
= SDL_GetTicks()*0.001-lasttime
;
1080 UpdateLogic(g
, dtime
*0.5);
1081 UpdateLogic(g
, dtime
*0.5);
1084 UpdateAndQueueDrawParticles(dtime
);
1087 //we don't want to waste cpu...
1095 int main(int argc
, char **argv
){