24 }TKeyBinding
;//TODO: s/int/real data type for a key
27 Vect Pos
; //where he is
28 Vect Move
; //how he want to move
29 Vect BSize
; //Size of bounding rect
30 Area
*Shape
; //how fat he is
31 //Area *TrShape; //translated Shape -- don't optimize yet
32 int Frags
; //no comment
34 double Speed
; //meters per second
35 int Orientation
; //1-up 2-left 3-down 4-right 0-down
36 int WannaShoot
; //1-want 0-don't want
37 double ReloadTime
; //time from last shot
38 int WannaDie
; //1-want suicide 2-died and still holding suicide 0-don't want
39 double AnimationTime
; //in seconds
54 int Exists
; // 0- doesn't exist 1-exists
65 Vect Vel
; //velocity i m/s
66 double Speed
; //for Templates
67 double Range
; //How far it can travel
69 int lid
; //who shoot this bullet?
70 int Exists
; // 0- doesn't exist 1-exists
71 double SFuzzy
; // Fuzzy factor for spawning 0-1 :)
72 double VFuzzy
; // Fuzzy factor for traveling 0-1 :)
77 TMap
*Map
; //where we are playing
78 TLilanek
*Lilanek
; //our heroes-ehm bad guys
81 TWeapon
*Weapon
; //Weapons lying on floor
83 TWeapon
*WeaponTemplate
;
84 TBullet
*BulletTemplate
;
85 int noWID
; //biggest WID, also number of WeaponTemplates
88 double PWeapondrop
; // Probability of weapon drop per second
116 void SwitchNextWeapon(Game
*g
, int lid
);
122 Orientations
[1].y
=-1;
123 Orientations
[2].x
=-1;
134 void SpawnLilanek(Game
*g
, int lid
){
143 for(tries
=0; tries
<1000; tries
++){ //TODO: remove exact number
144 Pos
.x
= RandD(0,g
->Map
->XX
);
145 Pos
.y
= RandD(0,g
->Map
->YY
);
147 tp
= TranslateArea(g
->Lilanek
[lid
].Shape
, &Pos
);
148 printf("%s\n", Area2String(tp
));
149 if(!AreaInMap(g
->Map
, tp
,0,1)){
153 for(olid
=0; olid
< g
->noLilaneks
; olid
++){
156 if(!g
->Lilanek
[olid
].Alive
){
159 oltp
= TranslateArea(g
->Lilanek
[olid
].Shape
, &g
->Lilanek
[olid
].Pos
);
160 if(AreaInArea(tp
, oltp
)){
170 g
->Lilanek
[lid
].Pos
.x
= Pos
.x
;
171 g
->Lilanek
[lid
].Pos
.y
= Pos
.y
;
172 g
->Lilanek
[lid
].Alive
= 1;
180 int RandWID(Game
*g
) {
181 int SumRandWeight
= 0;
184 for (i
=0; i
< g
->noWID
; i
++) {
185 SumRandWeight
+= g
->WeaponTemplate
[i
].RandomWeight
;
187 j
= RandI(0, SumRandWeight
);
188 for (i
=0; i
< g
->noWID
; i
++) {
189 j
-= g
->WeaponTemplate
[i
].RandomWeight
;
196 void DropWeapon(Game
*g
, int weapon
){
202 for(tries
=0; tries
<100; tries
++){ //TODO: remove exact number
203 Pos
.x
= RandD(0,g
->Map
->XX
);
204 Pos
.y
= RandD(0,g
->Map
->YY
);
206 tp
= TranslateArea(g
->WeaponTemplate
[WID
].Shape
, &Pos
);
207 if(AreaInMap(g
->Map
, tp
, 0, g
->Map
->noLayer
)){
210 memcpy(&g
->Weapon
[weapon
], &g
->WeaponTemplate
[WID
], sizeof(TWeapon
));
211 g
->Weapon
[weapon
].Shape
= g
->WeaponTemplate
[WID
].Shape
;
212 g
->Weapon
[weapon
].Pos
.x
= Pos
.x
;
213 g
->Weapon
[weapon
].Pos
.y
= Pos
.y
;
214 g
->Weapon
[weapon
].WID
= WID
;
215 g
->Weapon
[weapon
].Exists
= 1;
223 void DropWeapons(Game
*g
, double dtime
){
226 if( RandD(0.0, 1.0) >= (g
->PWeapondrop
*dtime
))
228 for(i
=0; i
< g
->noWeapons
; i
++){
229 if(g
->Weapon
[i
].Exists
)continue; //we don't like teleporting weapons :)
231 printf("A Weapon drop!\n");
233 break; //spawn max one weapon per update
237 void WeaponPickedUp(Game
*g
, double dtime
, int lid
, int wid
){
241 l
= &g
->Lilanek
[lid
];
244 l
->Ammo
[w
->WID
] += w
->Ammo
;
245 if(l
->Ammo
[w
->WID
] > w
->MaxAmmo
)
246 l
->Ammo
[w
->WID
] = w
->MaxAmmo
;
247 printf("Ammo: %d\n",l
->Ammo
[w
->WID
]);
248 l
->ActiveWeapon
= w
->WID
;
249 printf("AW: %d\n",l
->ActiveWeapon
);
256 void PickUpWeapons(Game
*g
, double dtime
){
260 for(lid
=0; lid
<g
->noLilaneks
; lid
++){
261 LArea
= TranslateArea(g
->Lilanek
[lid
].Shape
, &g
->Lilanek
[lid
].Pos
);
262 for(wid
=0; wid
< g
->noWeapons
; wid
++){
263 if(!g
->Weapon
[wid
].Exists
)
265 WArea
= TranslateArea(g
->Weapon
[wid
].Shape
, &g
->Weapon
[wid
].Pos
);
266 if(!AreaInArea( WArea
, LArea
)){
270 WeaponPickedUp(g
, dtime
, lid
, wid
);
277 void BulletExplodes(Game
*g
, int i
){
278 g
->Bullet
[i
].Exists
=0;
283 void MoveBullet(Game
*g
, double dtime
, int i
){
286 dp
.x
= g
->Bullet
[i
].Pos
.x
;
287 dp
.y
= g
->Bullet
[i
].Pos
.y
;
288 ff
= g
->Bullet
[i
].Speed
*g
->Bullet
[i
].VFuzzy
;
289 g
->Bullet
[i
].Pos
.x
+= (g
->Bullet
[i
].Vel
.x
+= RandD(-ff
,ff
))* dtime
;
290 g
->Bullet
[i
].Pos
.y
+= (g
->Bullet
[i
].Vel
.y
+= RandD(-ff
,ff
))* dtime
;
291 dp
.x
-= g
->Bullet
[i
].Pos
.x
;
292 dp
.y
-= g
->Bullet
[i
].Pos
.y
;
293 g
->Bullet
[i
].Range
-= sqrt(DotProduct(&dp
, &dp
));
296 void CollideBulletMap(Game
*g
, double dtime
, int i
){
299 p
=TranslateArea(g
->Bullet
[i
].Shape
, &g
->Bullet
[i
].Pos
);
300 if(AreaInMap(g
->Map
, p
, 1,1)==0)
301 BulletExplodes(g
, i
);
305 void BloodColorFunc(double temp
, SDL_Color
*c
)
307 SDL_Color col
={255,255,255,255};
308 col
.r
*=(0.5+0.5*temp
);
311 //col.unused *=temp*temp;
312 if (c
!= 0) memcpy(c
, &col
, sizeof(SDL_Color
));
315 void BloodParticles(Game
*g
, double dtime
, int lid
)
322 for(i
= 0; i
< 5; i
++){
323 p
= malloc(sizeof(Particle
));
324 memset(p
, 0, sizeof(Particle
));
325 a
= RandD(0.0, 20.0);
327 p
->x
= g
->Lilanek
[lid
].Pos
.x
-g
->Lilanek
[lid
].BSize
.x
*0.5;
328 p
->y
= g
->Lilanek
[lid
].Pos
.y
-g
->Lilanek
[lid
].BSize
.y
*0.5;
330 p
->vx
= v
*sin(a
) + g
->Lilanek
[lid
].Move
.x
;
331 p
->vy
= v
*cos(a
) + g
->Lilanek
[lid
].Move
.y
;
336 p
->tf
= &BloodColorFunc
;
342 void LilanekKilled(Game
*g
, double dtime
, int BulletID
, int LilanekID
){
344 g
->Bullet
[BulletID
].Exists
= 0;
345 g
->Lilanek
[LilanekID
].Deaths
++;
346 if (LilanekID
!= g
->Bullet
[BulletID
].lid
) {
347 g
->Lilanek
[g
->Bullet
[BulletID
].lid
].Frags
++;
349 g
->Lilanek
[g
->Bullet
[BulletID
].lid
].Frags
--;
351 BloodParticles(g
, dtime
, LilanekID
);
352 SpawnLilanek(g
, LilanekID
);
353 for(i
=0; i
<g
->noWID
; i
++){
354 g
->Lilanek
[LilanekID
].Ammo
[i
] = 0;
359 #define NO_EXPLOSIONS 10 //MAGIC_NUMBER
360 #define EXPLOSION_SPEED 5 //MAGIC_NUMBER
361 #define EXPLOSION_RANGE 1.0 //MAGIC_NUMBER
363 void SpawnExplosions(Game
*g
, double dtime
, int BulletID
){
370 Pos
.x
= g
->Bullet
[BulletID
].Pos
.x
;
371 Pos
.y
= g
->Bullet
[BulletID
].Pos
.y
;
372 for(i
=0; i
<NO_EXPLOSIONS
; i
++){
373 for(bid
=0; bid
<g
->noBullets
; bid
++){
374 if(g
->Bullet
[bid
].Exists
)
379 b
->Vel
.x
= RandD(0.0, 1.0)*(RandI(0,100)>50?-1:1);
380 b
->Vel
.y
= RandD(0.0, 1.0)*(RandI(0,100)>50?-1:1);
382 speed
= RandD(0.3, 1.0)*EXPLOSION_SPEED
;
387 b
->lid
= g
->Bullet
[BulletID
].lid
;
391 b
->Range
= EXPLOSION_RANGE
;
392 b
->Shape
= g
->Bullet
[BulletID
].Shape
;
393 printf("%lf ", speed
);
397 g
->Bullet
[BulletID
].Exists
= 0;
401 void CollideBulletLilanek(Game
*g
, double dtime
, int BulletID
){
405 BArea
=TranslateArea(g
->Bullet
[BulletID
].Shape
, &g
->Bullet
[BulletID
].Pos
);
406 for(LilanekID
=0; LilanekID
<g
->noLilaneks
; LilanekID
++){
407 LArea
=TranslateArea(g
->Lilanek
[LilanekID
].Shape
, &g
->Lilanek
[LilanekID
].Pos
);
408 if(AreaInArea(LArea
,BArea
)){
409 //if it is a mine, spawn explosion instead of killing instantly
410 if(g
->Bullet
[BulletID
].WID
== 1){
411 SpawnExplosions(g
, dtime
, BulletID
);
413 LilanekKilled(g
, dtime
, BulletID
, LilanekID
);
423 void UpdateBullets(Game
*g
, double dtime
){
425 for(BulletID
=0; BulletID
<g
->noBullets
; BulletID
++){
426 if(g
->Bullet
[BulletID
].Exists
==0)
427 continue; //We won't update non-existending bullets
428 MoveBullet(g
, dtime
, BulletID
);
429 if(g
->Bullet
[BulletID
].Range
< 0){
430 g
->Bullet
[BulletID
].Exists
= 0;
433 CollideBulletMap(g
, dtime
, BulletID
);
434 CollideBulletLilanek(g
, dtime
, BulletID
);
438 int CheckLilanekvsLilaneks(Game
*g
, Area
*a
, int LilanekID
){ //returns 0 if he collides with others, 1 if it's OK to move there
444 for(i
=0; i
<g
->noLilaneks
&& rval
==1; i
++){
447 nb
= TranslateArea(g
->Lilanek
[i
].Shape
, &g
->Lilanek
[i
].Pos
);
448 if(AreaInArea(nb
, a
))
456 void MoveLilaneks(Game
*g
, double dtime
){
463 for(i
=0; i
<g
->noLilaneks
; i
++){
464 //skip this Lilanek if he doesn't wanna move
465 if(g
->Lilanek
[i
].Move
.x
== 0.0 && g
->Lilanek
[i
].Move
.y
== 0.0)
467 for(dt
=dtime
, steps
=0; steps
<4; dt
/=2.0, steps
++){ //TODO: get rid of exact number
469 va
.x
= g
->Lilanek
[i
].Pos
.x
+ dt
*g
->Lilanek
[i
].Move
.x
;
470 va
.y
= g
->Lilanek
[i
].Pos
.y
+ dt
*g
->Lilanek
[i
].Move
.y
;
471 FreeArea(pa
); //we don't want memory leaks
472 pa
= TranslateArea(g
->Lilanek
[i
].Shape
, &va
);
473 //check for collision with map
474 if(AreaInMap(g
->Map
, pa
, 0, 1)==0)
475 continue; //try smaller dt if he collided with map
476 //check for collision with other Lilaneks
477 if(CheckLilanekvsLilaneks(g
, pa
, i
)==0)
479 //move him if we got here
480 g
->Lilanek
[i
].Pos
.x
+= dt
*g
->Lilanek
[i
].Move
.x
;
481 g
->Lilanek
[i
].Pos
.y
+= dt
*g
->Lilanek
[i
].Move
.y
;
485 FreeArea(pa
); //For sure
490 void ParseInput(Game
*g
, double dtime
){
496 keystate
= SDL_GetKeyState(NULL
);
509 for(i
=0; i
< g
->noLilaneks
; i
++){
510 curlil
= &g
->Lilanek
[i
];
513 if(keystate
[curlil
->Keys
.Up
]){
514 curlil
->Orientation
= 1;
515 curlil
->Move
.x
= curlil
->Speed
* Orientations
[1].x
;
516 curlil
->Move
.y
= curlil
->Speed
* Orientations
[1].y
;
520 if(keystate
[curlil
->Keys
.Down
]){
521 curlil
->Orientation
= 3;
522 curlil
->Move
.x
= curlil
->Speed
* Orientations
[3].x
;
523 curlil
->Move
.y
= curlil
->Speed
* Orientations
[3].y
;
527 if(keystate
[curlil
->Keys
.Left
]){
528 curlil
->Orientation
= 2;
529 curlil
->Move
.x
= curlil
->Speed
* Orientations
[2].x
;
530 curlil
->Move
.y
= curlil
->Speed
* Orientations
[2].y
;
534 if(keystate
[curlil
->Keys
.Right
]){
535 curlil
->Orientation
= 4;
536 curlil
->Move
.x
= curlil
->Speed
* Orientations
[4].x
;
537 curlil
->Move
.y
= curlil
->Speed
* Orientations
[4].y
;
546 if(keystate
[curlil
->Keys
.Shoot
]){
547 curlil
->WannaShoot
= 1;
549 curlil
->WannaShoot
= 0;
552 if(keystate
[curlil
->Keys
.Suicide
]){
553 if(curlil
->WannaDie
!= 2){
554 curlil
->WannaDie
= 1;
557 curlil
->WannaDie
= 0;
560 if(keystate
[curlil
->Keys
.Switch
]){
561 if(!curlil
->SwitchLock
){
562 SwitchNextWeapon(g
, i
);
563 curlil
->SwitchLock
= 1;
566 curlil
->SwitchLock
= 0;
571 void SpawnBullet(Game
*g
, double dtime
, int lid
, int bid
){
574 double vx
, vy
; //because we need to spawn also mines with no velocity
577 LArea
= TranslateArea(g
->Lilanek
[lid
].Shape
, &g
->Lilanek
[lid
]. Pos
);
579 bt
= &g
->BulletTemplate
[g
->Lilanek
[lid
].ActiveWeapon
];
580 memcpy (b
, bt
, sizeof(TBullet
));
582 b
->Pos
.x
= g
->Lilanek
[lid
].Pos
.x
+g
->Lilanek
[lid
].BSize
.x
*0.5;
583 b
->Pos
.y
= g
->Lilanek
[lid
].Pos
.y
+g
->Lilanek
[lid
].BSize
.y
*0.5;
585 b
->Range
= bt
->Range
;
586 b
->Vel
.x
= Orientations
[g
->Lilanek
[lid
].Orientation
].x
* b
->Speed
+RandD(-b
->Speed
*b
->SFuzzy
, b
->Speed
*b
->SFuzzy
);
587 b
->Vel
.y
= Orientations
[g
->Lilanek
[lid
].Orientation
].y
* b
->Speed
+RandD(-b
->Speed
*b
->SFuzzy
, b
->Speed
*b
->SFuzzy
);
588 if(DotProduct(&b
->Vel
, &b
->Vel
) <=0.01){
589 vx
= -1*Orientations
[g
->Lilanek
[lid
].Orientation
].x
;
590 vy
= -1*Orientations
[g
->Lilanek
[lid
].Orientation
].y
;
597 BArea
= TranslateArea(b
->Shape
, &b
->Pos
);
598 if(!AreaInArea(BArea
, LArea
))
600 b
->Pos
.x
+= vx
* dtime
*0.5;
601 b
->Pos
.y
+= vy
* dtime
*0.5;
606 void DustColorFunc(double temp
, SDL_Color
*c
)
608 SDL_Color col
={255,255,255,255};
612 col
.unused
*=temp
*temp
;
613 if (c
!= 0) memcpy(c
, &col
, sizeof(SDL_Color
));
616 void ShootParticles(Game
*g
, double dtime
, int lid
)
623 for(i
= 1; i
< 10; i
++){
624 p
= malloc(sizeof(Particle
));
625 memset(p
, 0, sizeof(Particle
));
626 a
= RandD(0.0, 2*M_PI
);
628 p
->x
= g
->Lilanek
[lid
].Pos
.x
-g
->Lilanek
[lid
].BSize
.x
*0.5;
629 p
->y
= g
->Lilanek
[lid
].Pos
.y
-g
->Lilanek
[lid
].BSize
.y
*0.5;
631 p
->vx
= v
*sin(a
) + g
->Lilanek
[lid
].Move
.x
;
632 p
->vy
= v
*cos(a
) + g
->Lilanek
[lid
].Move
.y
;
636 p
->tf
= &DustColorFunc
;
641 void Shoot(Game
*g
, double dtime
, int lid
){
645 for(i
=0; i
<g
->WeaponTemplate
[g
->Lilanek
[lid
].ActiveWeapon
].Burst
; i
++){
646 if(g
->Lilanek
[lid
].Ammo
[g
->Lilanek
[lid
].ActiveWeapon
] == 0)
648 for(bid
=0; bid
<g
->noBullets
; bid
++){
649 if(g
->Bullet
[bid
].Exists
)
651 SpawnBullet(g
, dtime
, lid
, bid
);
652 g
->Lilanek
[lid
].Ammo
[g
->Lilanek
[lid
].ActiveWeapon
]--;
653 g
->Lilanek
[lid
].ReloadTime
= 0;
657 ShootParticles(g
, dtime
, lid
);
658 switch(g
->Lilanek
[lid
].ActiveWeapon
){
659 case 0: PlaySound(s_shoot
); break;
660 case 1: PlaySound(s_mine
); break;
661 case 2: PlaySound(s_shoot
); break;
666 void SwitchNextWeapon(Game
*g
, int lid
){
669 l
= &g
->Lilanek
[lid
];
670 for(i
= 1; i
< g
->noWID
; i
++){
671 if(l
->Ammo
[(l
->ActiveWeapon
+i
)%(g
->noWID
)]){
672 l
->ActiveWeapon
= (l
->ActiveWeapon
+i
)%(g
->noWID
);
678 void ShootIfTheyWantTo(Game
*g
, double dtime
){
681 for(lid
=0; lid
<g
->noLilaneks
; lid
++){
682 //if(!g->Lilanek[lid].Exists)
684 if(g
->Lilanek
[lid
].Ammo
[g
->Lilanek
[lid
].ActiveWeapon
] == 0)
685 SwitchNextWeapon(g
,lid
);
687 if(g
->Lilanek
[lid
].ReloadTime
< g
->WeaponTemplate
[g
->Lilanek
[lid
].ActiveWeapon
].ReloadTime
){
688 g
->Lilanek
[lid
].ReloadTime
+= dtime
;
690 if(!g
->Lilanek
[lid
].WannaShoot
)
692 Shoot(g
, dtime
, lid
);
697 int UpdateLogic(Game
*g
,double dtime
){
699 DropWeapons(g
, dtime
);
700 UpdateBullets(g
, dtime
);
702 ParseInput(g
, dtime
);
704 MoveLilaneks(g
, dtime
);
705 PickUpWeapons(g
, dtime
);
706 ShootIfTheyWantTo(g
, dtime
);
708 return 0; //TODO: return something useful
711 Game
*testgame(){ //return testing game, function for use before we have some menu/loading mechanism
716 Config conf
= GetConfig();
718 g
= malloc(sizeof(Game
));
719 memset(g
, 0, sizeof(Game
));
721 g
->Map
= malloc(sizeof(TMap
));
723 g
->Map
->Layer
= malloc(sizeof(TMapLayer
*)*g
->Map
->noLayer
);
724 g
->Map
->Layer
[0] = malloc(sizeof(TMapLayer
));
725 g
->Map
->Layer
[0]->noFArea
= 1;
726 g
->Map
->Layer
[0]->FArea
= malloc(sizeof(Area
*) * g
->Map
->Layer
[0]->noFArea
);
727 p
= NewRect(4,2.5,3,2);
731 g
->Map
->Layer
[0]->FArea
[0] = a
;
733 g
->Map
->Layer
[1] = malloc(sizeof(TMapLayer
));
734 g
->Map
->Layer
[1]->noFArea
= 1;
735 g
->Map
->Layer
[1]->FArea
= malloc(sizeof(Area
*) * g
->Map
->Layer
[1]->noFArea
);
737 AddToPolyXY(p
, 0.30, 0.41);
738 AddToPolyXY(p
, 0.73, 0.41);
739 AddToPolyXY(p
, 0.77, 0.79);
740 AddToPolyXY(p
, 0.65, 0.955);
741 AddToPolyXY(p
, 0.365, 0.965);
742 AddToPolyXY(p
, 0.235, 0.785);
743 MultiplyPoly(p
, 4, 4);
744 pp
= TranslatePolyXY(p
, 7, 7);
749 g
->Map
->Layer
[1]->FArea
[0] = a
;
750 p
= NewRect(1,1,16,15);
754 g
->Map
->BoundingArea
= a
;
760 SetParticleBoundingBox(0,0,16,15);
764 g
->Map
->noSprites
= 2;
765 g
->Map
->Sprites
= (Sprite
**) malloc(sizeof(Sprite
*)*g
->Map
->noSprites
);
766 g
->Map
->SpritePos
= (Vect
*) malloc(sizeof(Vect
)*g
->Map
->noSprites
);
767 g
->Map
->SpritePos
[0].x
= 3.0;
768 g
->Map
->SpritePos
[0].y
= 1.0;
769 g
->Map
->SpritePos
[1].x
= 6.0;
770 g
->Map
->SpritePos
[1].y
= 6.0;
773 g
->Weapon
= malloc(sizeof(TWeapon
) * g
->noWeapons
);
775 fprintf(stderr
, "Cannot allocate memory for Weapons\n");
777 for(i
=0; i
<g
->noWeapons
; i
++){
778 g
->Weapon
[i
].Exists
= 0;
779 g
->Weapon
[i
].Shape
= 0;
783 g
->Lilanek
= malloc(sizeof(TLilanek
) * g
->noLilaneks
);
784 memset(g
->Lilanek
, 0, sizeof(TLilanek
) * g
->noLilaneks
);
785 g
->Lilanek
[0].BSize
.x
= 1;
786 g
->Lilanek
[0].BSize
.y
= 1;
787 //g->Lilanek[0].Shape = NewRect(0.6,0.2,0.8,1.6);
789 AddToPolyXY(p
, 1, 0);
790 AddToPolyXY(p
, 1.4, 0.2);
791 AddToPolyXY(p
, 1.66, 1.38);
792 AddToPolyXY(p
, 1.42, 2);
793 AddToPolyXY(p
, 0.6, 2);
794 AddToPolyXY(p
, 0.4, 1.46);
795 AddToPolyXY(p
, 0.66, 0.2);
796 MultiplyPoly(p
, 0.5*g
->Lilanek
[0].BSize
.x
, 0.5*g
->Lilanek
[0].BSize
.y
);
800 g
->Lilanek
[0].Shape
= a
;
801 g
->Lilanek
[0].Pos
.x
= 12;
802 g
->Lilanek
[0].Pos
.y
= 4;
803 g
->Lilanek
[0].Speed
= 4;
804 g
->Lilanek
[0].Alive
= 0;
805 g
->Lilanek
[0].Keys
.Up
= conf
.pl1_key_up
;
806 g
->Lilanek
[0].Keys
.Down
= conf
.pl1_key_down
;
807 g
->Lilanek
[0].Keys
.Left
= conf
.pl1_key_left
;
808 g
->Lilanek
[0].Keys
.Right
= conf
.pl1_key_right
;
809 g
->Lilanek
[0].Keys
.Shoot
= conf
.pl1_key_fire
;
810 g
->Lilanek
[0].Keys
.Suicide
= conf
.pl1_key_suicide
;
811 g
->Lilanek
[0].Keys
.Switch
= conf
.pl1_key_switch
;
812 g
->Lilanek
[0].Ammo
= malloc(sizeof(int)*g
->noWID
);
813 for(i
=0; i
<g
->noWID
; i
++){
814 g
->Lilanek
[0].Ammo
[i
] = 0;
816 g
->Lilanek
[0].ActiveWeapon
= 0;
818 SDL_Color red
= {255,211,211,255};
820 g
->Lilanek
[0].Color
= red
;
821 strcpy(g
->Lilanek
[0].Name
, redn
);
823 g
->Lilanek
[1].Alive
= 0; // little hack for SpawnLilanek to work
826 p
= g
->Lilanek
[0].Shape
->p
[0];
829 g
->Lilanek
[1].Shape
= a
;
830 g
->Lilanek
[1].BSize
.x
= g
->Lilanek
[0].BSize
.x
;
831 g
->Lilanek
[1].BSize
.y
= g
->Lilanek
[0].BSize
.y
;
832 g
->Lilanek
[1].Pos
.x
= 14;
833 g
->Lilanek
[1].Pos
.y
= 4;
834 g
->Lilanek
[1].Speed
= 4;
835 g
->Lilanek
[1].Alive
= 0;
836 g
->Lilanek
[1].Keys
.Up
= conf
.pl2_key_up
;
837 g
->Lilanek
[1].Keys
.Down
= conf
.pl2_key_down
;
838 g
->Lilanek
[1].Keys
.Left
= conf
.pl2_key_left
;
839 g
->Lilanek
[1].Keys
.Right
= conf
.pl2_key_right
;
840 g
->Lilanek
[1].Keys
.Shoot
= conf
.pl2_key_fire
;
841 g
->Lilanek
[1].Keys
.Suicide
= conf
.pl2_key_suicide
;
842 g
->Lilanek
[1].Keys
.Switch
= conf
.pl2_key_switch
;
843 g
->Lilanek
[1].Ammo
= malloc(sizeof(int)*g
->noWID
);
844 for(i
=0; i
<g
->noWID
; i
++){
845 g
->Lilanek
[1].Ammo
[i
] = 0;
847 g
->Lilanek
[1].ActiveWeapon
= 0;
849 SDL_Color blue
= {180,180,255, 255};
850 char bluen
[8]="Blue";
851 g
->Lilanek
[1].Color
= blue
;
852 strcpy(g
->Lilanek
[1].Name
, bluen
);
856 g
->WeaponTemplate
= malloc(sizeof(TWeapon
)*g
->noWID
);
857 p
= NewRect(0,0,0.5,0.5);
861 g
->WeaponTemplate
[0].Shape
= a
;
862 g
->WeaponTemplate
[0].WID
= 0;
863 g
->WeaponTemplate
[0].Exists
= 1;
864 g
->WeaponTemplate
[0].Ammo
= 30;
865 g
->WeaponTemplate
[0].MaxAmmo
= 120;
866 g
->WeaponTemplate
[0].ReloadTime
= 0.7;
867 g
->WeaponTemplate
[0].Burst
= 10;
868 g
->WeaponTemplate
[0].RandomWeight
= 10;
870 g
->BulletTemplate
= malloc(sizeof(TBullet
) * g
->noWID
);
871 p
= NewRect(0,0,0.1,0.1);
875 g
->BulletTemplate
[0].Shape
= a
;
876 g
->BulletTemplate
[0].WID
= 0;
877 g
->BulletTemplate
[0].Speed
= 20;
878 g
->BulletTemplate
[0].Range
= 20;
879 g
->BulletTemplate
[0].SFuzzy
= 0.160;
880 g
->BulletTemplate
[0].VFuzzy
= 0.000;
882 p
= NewRect(0,0,0.5,0.5);
886 g
->WeaponTemplate
[1].Shape
= a
;
887 g
->WeaponTemplate
[1].WID
= 1;
888 g
->WeaponTemplate
[1].Exists
= 1;
889 g
->WeaponTemplate
[1].Ammo
= 3;
890 g
->WeaponTemplate
[1].MaxAmmo
= 6;
891 g
->WeaponTemplate
[1].ReloadTime
= 0.5;
892 g
->WeaponTemplate
[1].Burst
= 1;
893 g
->WeaponTemplate
[1].RandomWeight
= 5;
895 p
= NewRect(0,0,0.5,0.5);
899 g
->BulletTemplate
[1].Shape
= a
;
900 g
->BulletTemplate
[1].WID
= 1;
901 g
->BulletTemplate
[1].Speed
= 0;
902 g
->BulletTemplate
[1].Range
= 20;
903 g
->BulletTemplate
[1].SFuzzy
= 0.0;
904 g
->BulletTemplate
[1].VFuzzy
= 0.0;
906 p
= NewRect(0,0,0.5,0.5);
910 g
->WeaponTemplate
[2].Shape
= a
;
911 g
->WeaponTemplate
[2].WID
= 0;
912 g
->WeaponTemplate
[2].Exists
= 1;
913 g
->WeaponTemplate
[2].Ammo
= 10;
914 g
->WeaponTemplate
[2].MaxAmmo
= 50;
915 g
->WeaponTemplate
[2].ReloadTime
= 0.1;
916 g
->WeaponTemplate
[2].Burst
= 1;
917 g
->WeaponTemplate
[2].RandomWeight
= 15;
919 p
= NewRect(0,0,0.1,0.1);
923 g
->BulletTemplate
[2].Shape
= a
;
924 g
->BulletTemplate
[2].WID
= 0;
925 g
->BulletTemplate
[2].Speed
= 20;
926 g
->BulletTemplate
[2].Range
= 20;
927 g
->BulletTemplate
[2].SFuzzy
= 0.040;
928 g
->BulletTemplate
[2].VFuzzy
= 0.010;
930 g
->Bullet
= malloc(sizeof(TBullet
) * g
->noBullets
);
931 for(i
=0; i
<g
->noBullets
; i
++){
932 g
->Bullet
[i
].Exists
= 0;
933 g
->Bullet
[i
].Shape
= 0;
936 g
->PWeapondrop
= 0.4;
948 Uint32
callback_fps(Uint32 interval
, void *param
)
951 event
.type
= SDL_USEREVENT
;
952 SDL_PushEvent(&event
);
957 SDL_Color
InvertColor(SDL_Color c
) {
969 QueueDrawSprite(bg
, 0.0, 0.0,-1.0);
970 for(i
=0; i
< g
->Map
->noSprites
; i
++)
971 QueueDrawSprite(g
->Map
->Sprites
[i
], g
->Map
->SpritePos
[i
].x
, g
->Map
->SpritePos
[i
].y
, g
->Map
->Sprites
[i
]->z
);
973 for(i
=0; i
< g
->noLilaneks
; i
++){
977 c
=g
->Lilanek
[i
].Color
;
978 if(g
->Lilanek
[i
].ReloadTime
< g
->WeaponTemplate
[g
->Lilanek
[i
].ActiveWeapon
].ReloadTime
){
984 QueueDrawSpriteColorize(lil
[g
->Lilanek
[i
].Orientation
], g
->Lilanek
[i
].Pos
.x
-1.0, g
->Lilanek
[i
].Pos
.y
-1.0, 1, c
);
985 QueueDrawSpriteColorize(hud
,16.0,4.0*i
, 1.0, c
);
986 switch(g
->Lilanek
[i
].ActiveWeapon
){
987 case 0: QueueDrawSprite(hud_brok
, 16.0, 0.0+4.0*i
,0.0);
989 case 1: QueueDrawSprite(hud_mine
, 16.0, 0.0+4.0*i
,0.0);
991 case 2: QueueDrawSprite(hud_kul
, 16.0, 0.0+4.0*i
,0.0);
994 pd
= (double)g
->Lilanek
[i
].Ammo
[g
->Lilanek
[i
].ActiveWeapon
]/(double)g
->WeaponTemplate
[g
->Lilanek
[i
].ActiveWeapon
].MaxAmmo
;
995 QueueDrawSpriteColorizeStretch(hud_ammo
, 18.0-2.0*pd
, 0.0+4.0*i
,4.0*pd
, 4.0, 2.0,c
);
996 pd
= (double)g
->Lilanek
[i
].ReloadTime
/(double)g
->WeaponTemplate
[g
->Lilanek
[i
].ActiveWeapon
].ReloadTime
;
998 QueueDrawSpriteColorizeStretch(hud_reload
, 18.0-2.0*pd
, 0.0+4.0*i
,4.0*pd
, 4.0, 2.0,c
);
999 snprintf (fragsbuf
, 16, "F: %d", g
->Lilanek
[i
].Frags
);
1000 QueueDrawTextColorize (fragsbuf
, 18.1, 4.0*i
+0.5, 4.0, InvertColor(g
->Lilanek
[i
].Color
));
1001 snprintf (fragsbuf
, 16, "D: %d", g
->Lilanek
[i
].Deaths
);
1002 QueueDrawTextColorize (fragsbuf
, 18.1, 4.0*i
+0.5*2.0, 4.0, InvertColor(g
->Lilanek
[i
].Color
));
1005 for(i
=0; i
< g
->noWeapons
; i
++)
1006 if(g
->Weapon
[i
].Exists
)
1007 switch(g
->Weapon
[i
].WID
){
1008 case 0: QueueDrawSprite(brok
, g
->Weapon
[i
].Pos
.x
- 1.0, g
->Weapon
[i
].Pos
.y
- 1.0,1.0);
1010 case 1: QueueDrawSprite(mines
, g
->Weapon
[i
].Pos
.x
- 1.0, g
->Weapon
[i
].Pos
.y
- 1.0,1.0);
1012 case 2: QueueDrawSprite(kul
, g
->Weapon
[i
].Pos
.x
- 1.0, g
->Weapon
[i
].Pos
.y
- 1.0,1.0);
1016 for(i
=0; i
< g
->noBullets
; i
++)
1017 if(g
->Bullet
[i
].Exists
)
1018 switch(g
->Bullet
[i
].WID
){
1019 case 0: QueueDrawSprite(kulka
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
1020 case 1: QueueDrawSprite(mine
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
1021 case 2: QueueDrawSprite(kulka
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
1022 case -1: QueueDrawSprite(explo
, g
->Bullet
[i
].Pos
.x
- 1.0, g
->Bullet
[i
].Pos
.y
- 1.0,1.0);break;
1027 int InitAll(Game
**g
){
1031 //TODO: odstranit SaveConfig... je to tu jenom kvuli debugovani
1034 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_TIMER
|SDL_INIT_AUDIO
) < 0) {
1035 fprintf(stderr
, "Unable to init SDL: %s\n", SDL_GetError());
1045 printf(PATH_GRAPHICS
"lil.svg");
1046 lil
[0] = LoadSpriteSVG(PATH_GRAPHICS
"lil.svg", 1.0, 1.0);
1047 lil
[1] = LoadSpriteSVG(PATH_GRAPHICS
"lilb.svg", 1.0, 1.0);
1048 lil
[2] = LoadSpriteSVG(PATH_GRAPHICS
"lill.svg", 1.0, 1.0);
1049 lil
[3] = LoadSpriteSVG(PATH_GRAPHICS
"lil.svg", 1.0, 1.0);
1050 lil
[4] = LoadSpriteSVG(PATH_GRAPHICS
"lilr.svg", 1.0, 1.0);
1051 (*g
)->Map
->Sprites
[0] = LoadSpriteSVG(PATH_GRAPHICS
"prek1.svg", 3.0, 3.0);
1052 (*g
)->Map
->Sprites
[1] = LoadSpriteSVG(PATH_GRAPHICS
"prek2.svg", 4.0, 4.0);
1053 (*g
)->Map
->Sprites
[0]->z
= 1;
1054 (*g
)->Map
->Sprites
[1]->z
= 1;
1056 bg
= LoadSpriteSVG(PATH_GRAPHICS
"bg.svg", 16.0, 15.0);
1057 kul
= LoadSpriteSVG(PATH_GRAPHICS
"kul.svg", 0.5, 0.5);
1058 explo
= LoadSpriteSVG(PATH_GRAPHICS
"exp.svg", 0.5, 0.5);
1059 dust
= LoadSpriteSVG(PATH_GRAPHICS
"dust.svg", 0.5, 0.5);
1060 blood
= LoadSpriteSVG(PATH_GRAPHICS
"blood.svg", 0.5, 0.5);
1061 brok
= LoadSpriteSVG(PATH_GRAPHICS
"brok.svg", 0.5, 0.5);
1062 kulka
= LoadSpriteSVG(PATH_GRAPHICS
"kulka.svg", 0.1, 0.1);
1063 mine
= LoadSpriteSVG(PATH_GRAPHICS
"mine.svg", 0.5, 0.5);
1064 mines
= LoadSpriteSVG(PATH_GRAPHICS
"mines.svg", 0.5, 0.5);
1065 hud
= LoadSpriteSVG(PATH_GRAPHICS
"hud.svg", 4.0, 4.0);
1066 hud_mine
= LoadSpriteSVG(PATH_GRAPHICS
"mines.svg", 2.2, 2.2);
1067 hud_kul
= LoadSpriteSVG(PATH_GRAPHICS
"kul.svg", 2.2, 2.2);
1068 hud_brok
= LoadSpriteSVG(PATH_GRAPHICS
"brok.svg", 2.2, 2.2);
1069 hud_ammo
= LoadSpriteSVG(PATH_GRAPHICS
"hud_ammo.svg", 4.0, 4.0);
1070 hud_reload
= LoadSpriteSVG(PATH_GRAPHICS
"hud_reload.svg", 4.0, 4.0);
1072 s_die
= LoadSound(PATH_SOUNDS
"die.wav");
1073 s_bonus
= LoadSound(PATH_SOUNDS
"bonus.wav");
1074 s_expl
= LoadSound(PATH_SOUNDS
"expl.wav");
1075 s_shoot
= LoadSound(PATH_SOUNDS
"shoot.wav");
1076 s_mine
= LoadSound(PATH_SOUNDS
"mine.wav");
1078 SDL_AddTimer(1000, callback_fps
, NULL
);
1083 int GameLoop(Game
*g
){
1086 double lasttime
, dtime
;
1088 lasttime
= SDL_GetTicks()*0.001;
1090 while (SDL_PollEvent(&event
)) {
1091 switch (event
.type
) {
1093 if (event
.key
.keysym
.sym
== SDLK_q
) {
1102 case SDL_VIDEORESIZE
:
1103 /* Resize the screen and redraw */
1105 conf
.screen_width
=event
.resize
.w
;
1106 conf
.screen_height
=event
.resize
.h
;
1109 InvalidateSprites();
1113 printf("%d frames\n",frames
);
1121 dtime
= SDL_GetTicks()*0.001-lasttime
;
1127 UpdateLogic(g
, dtime
*0.5);
1128 UpdateLogic(g
, dtime
*0.5);
1131 UpdateAndQueueDrawParticles(dtime
);
1134 //we don't want to waste cpu...
1142 int main(int argc
, char **argv
){