Skip to content

Commit

Permalink
Improve bullet code, fix warnings, clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
bl0ckeduser committed Dec 3, 2011
1 parent eb61995 commit 9af674f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 35 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
fixed version.
+ Optimizied key and door models; game runs at full speed

- Optimize bullets ? They seem to cause some lag
- Add lighting/shininess/antialiasing/you-name-it effects
to make things nicer

Expand Down
29 changes: 15 additions & 14 deletions bullet.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ game_obj* newBullet(game_obj* list, float x, float y, float z, float angle)
bul->data[BULLET_ZDIR] = my_cos(bul->data[BULLET_ANGLE]);
#endif

/* collision system movement vector */
/* collision data */
bul->box.min.x = (float)(bul->data[BULLET_X] - 5);
bul->box.min.y = (float)(bul->data[BULLET_Y] - 5);
bul->box.min.z = (float)(bul->data[BULLET_Z] - 5);
bul->box.max.x = (float)(bul->data[BULLET_X] + 5);
bul->box.max.y = (float)(bul->data[BULLET_Y] + 5);
bul->box.max.z = (float)(bul->data[BULLET_Z] + 5);
bul->box.move.x = (float)10*bul->data[BULLET_XDIR];
bul->box.move.y = (float)0;
bul->box.move.z = (float)10*bul->data[BULLET_ZDIR];
Expand All @@ -41,14 +47,10 @@ void bulletTick(game_obj* bul)

bul->data[BULLET_X] += 20 * bul->data[BULLET_XDIR] * dtime;
bul->data[BULLET_Z] += 20 * bul->data[BULLET_ZDIR] * dtime;

/* bullet collision box */
bul->box.min.x = (float)(bul->data[BULLET_X] - 5);
bul->box.min.y = (float)(bul->data[BULLET_Y] - 5);
bul->box.min.z = (float)(bul->data[BULLET_Z] - 5);
bul->box.max.x = (float)(bul->data[BULLET_X] + 5);
bul->box.max.y = (float)(bul->data[BULLET_Y] + 5);
bul->box.max.z = (float)(bul->data[BULLET_Z] + 5);
bul->box.min.x += 20 * bul->data[BULLET_XDIR] * dtime;
bul->box.max.x += 20 * bul->data[BULLET_XDIR] * dtime;
bul->box.min.z += 20 * bul->data[BULLET_ZDIR] * dtime;
bul->box.max.z += 20 * bul->data[BULLET_ZDIR] * dtime;

if((bul->data[BULLET_TIMER] -= 3*dtime) < 0.0)
if(!bul->data[BULLET_EXPLODED])
Expand All @@ -65,9 +67,8 @@ void bulletCollide(game_obj* a, game_obj* b)

void bulletDraw(game_obj* bul)
{
glTranslatef((GLfloat)bul->data[BULLET_X]/10.0f, (GLfloat)bul->data[BULLET_Y]/10.0f,
(GLfloat)bul->data[BULLET_Z]/10.0f);
glScalef(0.1f, 0.1f, 0.1f);
glRotatef(bul->data[BULLET_ANGLE], 0.0f, 1.0f, 0.0f);
drawModelWithGL(bulletModel);
glTranslatef((GLfloat)bul->data[BULLET_X]/10.0f, (GLfloat)bul->data[BULLET_Y]/10.0f,
(GLfloat)bul->data[BULLET_Z]/10.0f);
glRotatef(bul->data[BULLET_ANGLE], 0.0f, 1.0f, 0.0f);
drawModelWithGL(bulletModel);
}
Binary file modified clown3d-DS.elf
Binary file not shown.
Binary file modified clown3d-DS.nds
Binary file not shown.
11 changes: 8 additions & 3 deletions headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ enum
typedef struct
{
int* vertnum; /* array of vertex numbers */
int point_count; /* triangle or quad ? the DS has to know ! */
void* next; /* pointer to next face */
int point_count; /* triangle or quad ? the DS has to know ! */
void* next; /* pointer to next face */
} face;

/* Vertex */
Expand All @@ -161,7 +161,7 @@ typedef struct
{
float color[3]; /* group color */
face* faces; /* faces linked list */
void* next; /* next group */
void* next; /* next group */
} model_group;

/* Model */
Expand Down Expand Up @@ -254,6 +254,11 @@ extern void initFunction(void *va);
extern void tickFunction(void *va);
extern void drawFunction(void* va);
extern void collisionFunction(void* va, void* vb);

extern void gc_push(game_obj* ptr);
extern void gc_collect(void);
extern void gc_stop(void);


#endif

Expand Down
1 change: 1 addition & 0 deletions mem-check.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include <stdlib.h>
#include <stdio.h>

size_t tot = 0;

Expand Down
16 changes: 8 additions & 8 deletions model-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

char bullet_model[] = "newgroup \
color 255 255 0 \
vertex -1 -0.5 0.5 \
vertex -1 0.5 0.5 \
vertex 1 -0.5 0.5 \
vertex 1 0.5 0.5 \
vertex 1 -0.5 -0.5 \
vertex 1 0.5 -0.5 \
vertex -1 -0.5 -0.5 \
vertex -1 0.5 -0.5 \
vertex -.1 -.05 .05 \
vertex -.1 .05 .05 \
vertex .1 -.05 .05 \
vertex .1 .05 .05 \
vertex .1 -.05 -.05 \
vertex .1 .05 -.05 \
vertex -.1 -.05 -.05 \
vertex -.1 .05 -.05 \
face 1 2 4 3 \
face 3 4 6 5 \
face 5 6 8 7 \
Expand Down
1 change: 1 addition & 0 deletions model-load.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> /* fabs */
#include "headers.h"

/* On the DS, loadModel() is slow.
Expand Down
20 changes: 10 additions & 10 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void playerTick(game_obj* player)
#ifdef PC_TARGET
shoot = keystate[SDLK_s];
jump = keystate[SDLK_z];
left = keystate[SDLK_RIGHT];
right = keystate[SDLK_LEFT];
left = keystate[SDLK_LEFT];
right = keystate[SDLK_RIGHT];
down = keystate[SDLK_DOWN];
up = keystate[SDLK_UP];
#else
Expand All @@ -94,8 +94,8 @@ void playerTick(game_obj* player)
u16 keys = keysHeld();
shoot = (keys & KEY_A);
jump = (keys & KEY_B);
left = (keys & KEY_RIGHT);
right = (keys & KEY_LEFT);
left = (keys & KEY_LEFT);
right = (keys & KEY_RIGHT);
down = (keys & KEY_DOWN);
up = (keys & KEY_UP);
#endif
Expand All @@ -112,17 +112,17 @@ void playerTick(game_obj* player)
if(shoot && player->data[PLAYER_BULLET_TIMER] <= 0.1f)
{
player->data[PLAYER_BULLET_TIMER] = 25.0;
newBullet(player, player->data[PLAYER_X] + player->data[PLAYER_DIRX] * 10,
newBullet(player, player->data[PLAYER_X] + player->data[PLAYER_DIRX] * 15,
player->data[PLAYER_Y],
player->data[PLAYER_Z] + player->data[PLAYER_DIRZ] * 10,
player->data[PLAYER_Z] + player->data[PLAYER_DIRZ] * 15,
player->data[PLAYER_ANGLE]);
}

if(left)
player->data[PLAYER_ANGLE] -= 9.0 * dtime;
player->data[PLAYER_ANGLE] += 9.0 * dtime;

if(right)
player->data[PLAYER_ANGLE] += 9.0 * dtime;
player->data[PLAYER_ANGLE] -= 9.0 * dtime;

if(up) {
player->data[PLAYER_MOVEX] = 7.5 *
Expand All @@ -132,9 +132,9 @@ void playerTick(game_obj* player)
}

if(down) {
player->data[PLAYER_MOVEX] = -7 *
player->data[PLAYER_MOVEX] = -7.5 *
player->data[PLAYER_DIRX] * dtime;
player->data[PLAYER_MOVEZ] = -7 *
player->data[PLAYER_MOVEZ] = -7.5 *
player->data[PLAYER_DIRZ] * dtime;
}

Expand Down
2 changes: 2 additions & 0 deletions string-read.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* read tokens from text data stored in ROM */

#include <stdio.h>

char str[1024];
int i;
float f;
Expand Down

0 comments on commit 9af674f

Please sign in to comment.