Skip to content

Commit

Permalink
Done
Browse files Browse the repository at this point in the history
  • Loading branch information
theZiz committed Jul 23, 2014
1 parent 2200289 commit 3956c79
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 209 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ SDL = `sdl-config --cflags`

SPARROW_FOLDER = ../sparrow3d

TARGET = nativ
#TARGET = nativ

ifdef TARGET
include $(SPARROW_FOLDER)/target-files/$(TARGET).mk

TARGET = pandora
#TARGET = pandora

BUILD = ./build/$(TARGET)/hase
SPARROW_LIB = $(SPARROW_FOLDER)/build/$(TARGET)/sparrow3d
Expand Down
146 changes: 71 additions & 75 deletions bullet.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pBullet shootBullet(int x,int y,int direction,int power,Sint32 dr)
bullet->y = y+(10+BULLET_SIZE)*spSin(direction);
bullet->dr = dr;
bullet->impact_state = 0;
bullet->rotation = rand()%(2*SP_PI);
bullet->rotation = spRand()%(2*SP_PI);
bullet->dx = spMul(spCos(direction),power);
bullet->dy = spMul(spSin(direction),power);
return bullet;
Expand Down Expand Up @@ -180,91 +180,87 @@ void bullet_impact(int X,int Y,int radius)
spSelectRenderTarget(screen);
}

int updateBullets(int steps)
int updateBullets()
{
int i;
for (i = 0; i < steps; i++)
pBullet momBullet = firstBullet;
pBullet before = NULL;
while (momBullet)
{
pBullet momBullet = firstBullet;
pBullet before = NULL;
while (momBullet)
momBullet->dx -= gravitation_x(momBullet->x >> SP_ACCURACY,momBullet->y >> SP_ACCURACY) >> PHYSIC_IMPACT;
momBullet->dy -= gravitation_y(momBullet->x >> SP_ACCURACY,momBullet->y >> SP_ACCURACY) >> PHYSIC_IMPACT;
int speed = abs(momBullet->dx)+abs(momBullet->dy);
momBullet->rotation+=momBullet->dr*speed/BULLET_SPEED_DOWN;
int dead = 0;
if (momBullet->impact_state == 0 &&
circle_is_empty(momBullet->x+momBullet->dx >> SP_ACCURACY,momBullet->y+momBullet->dy >> SP_ACCURACY,BULLET_SIZE,-1))
{
momBullet->dx -= gravitation_x(momBullet->x >> SP_ACCURACY,momBullet->y >> SP_ACCURACY) >> PHYSIC_IMPACT;
momBullet->dy -= gravitation_y(momBullet->x >> SP_ACCURACY,momBullet->y >> SP_ACCURACY) >> PHYSIC_IMPACT;
int speed = abs(momBullet->dx)+abs(momBullet->dy);
momBullet->rotation+=momBullet->dr*speed/BULLET_SPEED_DOWN;
int dead = 0;
if (momBullet->impact_state == 0 &&
circle_is_empty(momBullet->x+momBullet->dx >> SP_ACCURACY,momBullet->y+momBullet->dy >> SP_ACCURACY,BULLET_SIZE,-1))
{
momBullet->x += momBullet->dx;
momBullet->y += momBullet->dy;
}
else
momBullet->x += momBullet->dx;
momBullet->y += momBullet->dy;
}
else
{
int j;
switch (momBullet->impact_state)
{
int j;
switch (momBullet->impact_state)
{
case 0:
momBullet->impact_state = 1;
case 0:
momBullet->impact_state = 1;
momBullet->impact_counter = IMPACT_TIME;
break;
case 1:
momBullet->impact_counter--;
if (momBullet->impact_counter == 0)
{
momBullet->impact_state = 2;
momBullet->impact_counter = IMPACT_TIME;
break;
case 1:
momBullet->impact_counter--;
if (momBullet->impact_counter == 0)
spClearTarget(EXPLOSION_COLOR);
spFlip();
bullet_impact(momBullet->x >> SP_ACCURACY,momBullet->y >> SP_ACCURACY,32);
for (j = 0; j < player_count; j++)
{
momBullet->impact_state = 2;
momBullet->impact_counter = IMPACT_TIME;
spClearTarget(EXPLOSION_COLOR);
spFlip();
bullet_impact(momBullet->x >> SP_ACCURACY,momBullet->y >> SP_ACCURACY,32);
for (j = 0; j < player_count; j++)
if (player[j]->health == 0)
continue;
int d = spFixedToInt(player[j]->x-momBullet->x)*spFixedToInt(player[j]->x-momBullet->x)+
spFixedToInt(player[j]->y-momBullet->y)*spFixedToInt(player[j]->y-momBullet->y);
d = 1024-d;
if (d > 0)
player[j]->health -= d*MAX_HEALTH/2048;
if (player[j]->health <= 0)
{
if (player[j]->health == 0)
continue;
int d = spFixedToInt(player[j]->x-momBullet->x)*spFixedToInt(player[j]->x-momBullet->x)+
spFixedToInt(player[j]->y-momBullet->y)*spFixedToInt(player[j]->y-momBullet->y);
d = 1024-d;
if (d > 0)
player[j]->health -= d*MAX_HEALTH/2048;
if (player[j]->health <= 0)
{
player[j]->health = 0;
alive_count--;
}
player[j]->health = 0;
alive_count--;
}
spResetLoop();
return 2;
}
break;
case 2:
momBullet->impact_counter--;
if (momBullet->impact_counter == 0)
{
dead = 1;
if (alive_count < 2)
return 1;
}
break;
}
}
if (dead || momBullet->x < 0 || momBullet->y < 0 || spFixedToInt(momBullet->x) >= LEVEL_WIDTH || spFixedToInt(momBullet->y) >= LEVEL_HEIGHT)
{
if (momBullet == player[active_player]->bullet)
next_player();
if (before)
before->next = momBullet->next;
else
firstBullet = momBullet->next;
pBullet next = momBullet->next;
free(momBullet);
momBullet = next;
spResetLoop();
return 2;
}
break;
case 2:
momBullet->impact_counter--;
if (momBullet->impact_counter == 0)
{
dead = 1;
if (alive_count < 2)
return 1;
}
break;
}
}
if (dead || momBullet->x < 0 || momBullet->y < 0 || spFixedToInt(momBullet->x) >= LEVEL_WIDTH || spFixedToInt(momBullet->y) >= LEVEL_HEIGHT)
{
if (momBullet == player[active_player]->bullet)
next_player();
if (before)
before->next = momBullet->next;
else
{
before = momBullet;
momBullet = momBullet->next;
}
firstBullet = momBullet->next;
pBullet next = momBullet->next;
free(momBullet);
momBullet = next;
}
else
{
before = momBullet;
momBullet = momBullet->next;
}
}
return 0;
Expand Down
4 changes: 2 additions & 2 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ void set_status(pGame game,int status)
//Shuffle
for (i=0;i<game->player_count*10;i++)
{
int a = rand()%game->player_count;
int b = rand()%game->player_count;
int a = spRand()%game->player_count;
int b = spRand()%game->player_count;
if (a == b)
continue;
int temp = positions[a];
Expand Down
Binary file modified data/hase9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 69 additions & 41 deletions hase.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void draw(void)
spEllipse(screen->w/2+(spMul(player[active_player]->x-posX,zoom) >> SP_ACCURACY),screen->h/2+(spMul(player[active_player]->y-posY-spIntToFixed(14),zoom) >> SP_ACCURACY),0,
spFixedToInt(zoom*6*(player[active_player]->health)/MAX_HEALTH)+1,
spFixedToInt(zoom*6*(player[active_player]->health)/MAX_HEALTH)+1,spGetRGB(0,255,0));

//spFontDrawMiddle( screen->w/2+(spMul(player[active_player]->x-posX,zoom) >> SP_ACCURACY),screen->h/2+(spMul(player[active_player]->y-posY-spIntToFixed(10),zoom) >> SP_ACCURACY)-font->maxheight/2,0,"100", font );
if (player[active_player]->computer)
sprintf(buffer,"%s (AI)",player[active_player]->name);
Expand All @@ -116,6 +117,11 @@ void draw(void)
spSetBlending( SP_ONE*2/3 );
spFontDrawMiddle( screen->w/2+(spMul(player[active_player]->x-posX,zoom) >> SP_ACCURACY),screen->h/2+(spMul(player[active_player]->y-posY-spIntToFixed(14),zoom) >> SP_ACCURACY),0,buffer, font );
spSetBlending( SP_ONE );
if (player[active_player]->computer && ai_shoot_tries>1)
{
sprintf(buffer,"Aiming (%2i%%)",ai_shoot_tries*100/AI_MAX_TRIES);
spFontDrawMiddle( screen->w/2+(spMul(player[active_player]->x-posX,zoom) >> SP_ACCURACY),screen->h/2+(spMul(player[active_player]->y-posY-spIntToFixed(4),zoom) >> SP_ACCURACY),0,buffer, font );
}

//Not the player:
int not_active_player;
Expand Down Expand Up @@ -201,22 +207,23 @@ int jump(int high)

int min_d_not_me(int x,int y,int me)
{
int min_d = 10000;
int min_d = LEVEL_WIDTH*LEVEL_WIDTH;
int i;
int my_d = spFixedToInt(player[me]->x-x)*spFixedToInt(player[me]->x-x)+
spFixedToInt(player[me]->y-y)*spFixedToInt(player[me]->y-y);
if (my_d < 256)
min_d*=2;
else
for (i = 0; i < 0;i++)
{
if (i == me)
continue;
int d = spFixedToInt(player[i]->x-x)*spFixedToInt(player[i]->x-x)+
spFixedToInt(player[i]->y-y)*spFixedToInt(player[i]->y-y);
if (d < min_d)
min_d = d;
}
if (my_d < 1024)
return LEVEL_WIDTH*LEVEL_WIDTH;
for (i = 0; i < player_count;i++)
{
if (i == me)
continue;
if (player[i]->health == 0)
continue;
int d = spFixedToInt(player[i]->x-x)*spFixedToInt(player[i]->x-x)+
spFixedToInt(player[i]->y-y)*spFixedToInt(player[i]->y-y);
if (d < min_d)
min_d = d;
}
return min_d;
}

Expand Down Expand Up @@ -429,8 +436,8 @@ int calc(Uint32 steps)
if (goal > -SP_PI/2 && rotation < -SP_PI*3/2)
rotation += 2*SP_PI;
rotation = rotation*127/128+goal/128;
update_player(1);
int res = do_physics(1);
update_player();
int res = do_physics();
if (res == 1)
result = 2;
if (res)
Expand All @@ -455,34 +462,45 @@ int calc(Uint32 steps)
//AI
if (player[active_player]->shoot == 0)
{
if (player[active_player]->bums)
if (player[active_player]->bums && player[active_player]->hops <= 0)
{
int j;
for (j = 0; j < AI_TRIES_PER_FRAME; j++)
if (ai_shoot_tries == 0)
{
ai_shoot_tries++;
if (ai_shoot_tries < AI_MAX_TRIES)
jump((spRand()%4==0)?1:0);
if (spRand()%4 == 0)
ai_shoot_tries = 1;
}
else
{
if (last_ai_try < AI_TRIES_EVERY_MS)
last_ai_try++;
else
{
//Lets first try...
int x = player[active_player]->x;
int y = player[active_player]->y;
int w_d = rand()%(2*SP_PI);
int w_p = rand()%SP_ONE;
lastPoint(&x,&y,player[active_player]->rotation+w_d+SP_PI,w_p/2);
int d = min_d_not_me(x,y,active_player);
if (d < lastAIDistance)
last_ai_try = 0;
ai_shoot_tries++;
if (ai_shoot_tries < AI_MAX_TRIES)
{
lastAIDistance = d;
player[active_player]->w_direction = w_d;
player[active_player]->w_power = w_p;
//Lets first try...
int x = player[active_player]->x;
int y = player[active_player]->y;
int w_d = spRand()%(2*SP_PI);
int w_p = spRand()%SP_ONE;
lastPoint(&x,&y,player[active_player]->rotation+w_d+SP_PI,w_p/2);
int d = min_d_not_me(x,y,active_player);
if (d < lastAIDistance)
{
lastAIDistance = d;
player[active_player]->w_direction = w_d;
player[active_player]->w_power = w_p;
}
}
else
{
//Shoot!
player[active_player]->shoot = 1;
player[active_player]->bullet = shootBullet(player[active_player]->x,player[active_player]->y,player[active_player]->w_direction+player[active_player]->rotation+SP_PI,player[active_player]->w_power/2,player[active_player]->direction?1:-1);
break;
}
}
else
{
//Shoot!
player[active_player]->shoot = 1;
player[active_player]->bullet = shootBullet(player[active_player]->x,player[active_player]->y,player[active_player]->w_direction+player[active_player]->rotation+SP_PI,player[active_player]->w_power/2,player[active_player]->direction?1:-1);
break;
}
}
}
Expand All @@ -491,7 +509,7 @@ int calc(Uint32 steps)
{
//RUNNING!
if (player[active_player]->bums && player[active_player]->hops <= 0)
jump((rand()%4==0)?1:0);
jump((spRand()%4==0)?1:0);
}
}
else
Expand Down Expand Up @@ -581,8 +599,11 @@ int calc(Uint32 steps)
}
if (player[active_player]->shoot == 0)
updateTrace();
if (input_states[INPUT_BUTTON_SELECT])
if (spGetInput()->button[SP_BUTTON_SELECT])
{
spGetInput()->button[SP_BUTTON_SELECT] = 0;
return 1;
}
return result;
}

Expand All @@ -608,7 +629,13 @@ int hase(void ( *resize )( Uint16 w, Uint16 h ),pGame game,pPlayer me_list)
}
p = p->next;
}
srand(0);
//Getting a deterministic seed
Uint32 f[4] = {123,123,123,123};
int k;
for (k = 0; k < 4 && game->name[k]; k++)
f[k] = game->name[k];
Uint32 seed = f[0]+f[1]*256+f[2]*65536+f[3]*16777216;
spSetRand(seed);
loadInformation("Loading images...");
arrow = spLoadSurface("./data/gravity.png");
weapon = spLoadSurface("./data/weapon.png");
Expand Down Expand Up @@ -638,6 +665,7 @@ int hase(void ( *resize )( Uint16 w, Uint16 h ),pGame game,pPlayer me_list)
game_pause = 0;

int result = spLoop(draw,calc,10,resize,NULL);

stop_thread();
if (result == 2)
{
Expand Down
Loading

0 comments on commit 3956c79

Please sign in to comment.