Compare commits
2 Commits
000a5cfe90
...
be581bbe70
Author | SHA1 | Date | |
---|---|---|---|
be581bbe70 | |||
663bd8d990 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
.vscode/*
|
||||
.vs/*
|
||||
bin/*
|
||||
src/gfx/convpng.*
|
||||
screenshot.png
|
||||
|
843
obj/main.src
843
obj/main.src
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,9 @@
|
||||
## Spacemania TI-84 CE Edition
|
||||
### Now almost working!
|
||||
Will post a release later, for now, you can compile it for yourself with the tools from [CE-Programming](https://github.com/CE-Programming/)
|
||||
This being my first project programming in C I, quite frankly, have no clue what I'm doing. At this point, the program works fine and technically the game is playable. Enemy's die if you hit them and you die if they hit you, however, the game is extremely slow and I don't know how to fix it. I have decided to continue working on something which runs on more capable hardware and which is in a language I already know. Maybe I'll come back to this later, maybe I wont, you'll have to see.
|
||||
|
||||
Feel free to improve the code if you know how.
|
||||
|
||||
You can compile it for yourself with the tools from [CE-Programming](https://github.com/CE-Programming/)
|
||||
|
||||
|
||||
|
10
src/baddie.h
10
src/baddie.h
@ -7,6 +7,11 @@ struct Baddie {
|
||||
float x;
|
||||
float y;
|
||||
} pos;
|
||||
struct oldPos
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
} oldPos;
|
||||
} baddies[baddieAmount];
|
||||
|
||||
int spawnBaddie(float posX, float posY)
|
||||
@ -31,7 +36,12 @@ int updateBaddie(int i)
|
||||
if (!(baddies[i].pos.x <= (0 - 32)))
|
||||
{
|
||||
baddies[i].pos.x -= speed;
|
||||
if ((abs(baddies[i].oldPos.x - baddies[i].pos.x) >= 1) || (abs(baddies[i].oldPos.y - baddies[i].pos.y) >= 1))
|
||||
{
|
||||
gfx_Sprite(baddie, baddies[i].pos.x, baddies[i].pos.y);
|
||||
baddies[i].oldPos.x = baddies[i].pos.x;
|
||||
baddies[i].oldPos.y = baddies[i].pos.y;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
10
src/bullet.h
10
src/bullet.h
@ -9,6 +9,11 @@ struct Bullet
|
||||
float x;
|
||||
float y;
|
||||
} pos;
|
||||
struct oldPos
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
} oldPos;
|
||||
} bullets[bulletAmount];
|
||||
|
||||
int spawnBullet(float posX, float posY)
|
||||
@ -33,7 +38,12 @@ int updateBullet(int i)
|
||||
if (!(bullets[i].pos.x >= (LCD_WIDTH + 16)))
|
||||
{
|
||||
bullets[i].pos.x += speed;
|
||||
if ((abs(bullets[i].oldPos.x - bullets[i].pos.x) >= 1) || (abs(bullets[i].oldPos.y - bullets[i].pos.y) >= 1))
|
||||
{
|
||||
gfx_Sprite(bullet, bullets[i].pos.x, bullets[i].pos.y);
|
||||
bullets[i].oldPos.x = bullets[i].pos.x;
|
||||
bullets[i].oldPos.y = bullets[i].pos.y;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
40
src/collision.h
Normal file
40
src/collision.h
Normal file
@ -0,0 +1,40 @@
|
||||
// Variables for collision detection
|
||||
float distance = 0;
|
||||
float difference[2];
|
||||
int a;
|
||||
|
||||
// Check collisions
|
||||
void checkCollision() {
|
||||
for (i = 0; i < (baddieAmount - 1); i++)
|
||||
{
|
||||
// Collision baddie x bullet
|
||||
for (a = 0; a < (bulletAmount - 1); a++)
|
||||
{
|
||||
//// Difference x
|
||||
difference[0] = (baddies[i].pos.x + (32 / 2)) - (bullets[a].pos.x + (16 / 2));
|
||||
//// Difference y
|
||||
difference[1] = (baddies[i].pos.y + (32 / 2)) - (bullets[a].pos.y + (16 / 2));
|
||||
|
||||
// Calculate diffence
|
||||
distance = sqrt(pow(difference[0], 2) + pow(difference[1], 2));
|
||||
if (!baddies[i].dead && !bullets[a].dead && distance <= 11)
|
||||
{
|
||||
bullets[a].dead = true;
|
||||
baddies[i].dead = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Collision baddie x player
|
||||
//// Difference x
|
||||
difference[0] = (baddies[i].pos.x + (32 / 2)) - (player.pos.x + (32 / 2));
|
||||
//// Difference y
|
||||
difference[1] = (baddies[i].pos.y + (32 / 2)) - (player.pos.y + (32 / 2));
|
||||
|
||||
// Calculate diffence
|
||||
distance = sqrt(pow(difference[0], 2) + pow(difference[1], 2));
|
||||
if (!baddies[i].dead && distance <= 15)
|
||||
{
|
||||
// Gameover
|
||||
}
|
||||
}
|
||||
}
|
10
src/main.c
10
src/main.c
@ -15,15 +15,19 @@
|
||||
|
||||
// set global vars
|
||||
const int bulletAmount = 5;
|
||||
const int baddieAmount = 32;
|
||||
const int baddieAmount = 12;
|
||||
int spriteActive = 0;
|
||||
int gamestate = 0;
|
||||
float speed = 0.5;
|
||||
int i;
|
||||
float t;
|
||||
float dt;
|
||||
|
||||
// Include entity headers
|
||||
#include "player.h"
|
||||
#include "bullet.h"
|
||||
#include "baddie.h"
|
||||
#include "collision.h"
|
||||
#include "controls.h"
|
||||
|
||||
void setup()
|
||||
@ -32,8 +36,6 @@ void setup()
|
||||
|
||||
/* Initialize the 8bpp graphics */
|
||||
gfx_Begin();
|
||||
dbg_sprintf(dbgout, "This is the start of a CEmu debugging test\n");
|
||||
dbg_Debugger();
|
||||
|
||||
/* Set up the palette for our sprites */
|
||||
gfx_SetPalette(sprites_pal, sizeof_sprites_pal, 0);
|
||||
@ -92,6 +94,8 @@ void main(void)
|
||||
|
||||
}
|
||||
|
||||
checkCollision();
|
||||
|
||||
// Redraw player if position has changed or if a bullet has been fired
|
||||
updatePlayer(spriteActive);
|
||||
|
||||
|
@ -13,9 +13,9 @@ struct Player
|
||||
} oldPos;
|
||||
} player;
|
||||
|
||||
void updatePlayer(int bulletsAlive)
|
||||
void updatePlayer(int spriteActive)
|
||||
{
|
||||
if ((abs(player.oldPos.x - player.pos.x) >= 1) || (abs(player.oldPos.y - player.pos.y) >= 1) || bulletsAlive == 1)
|
||||
if ((abs(player.oldPos.x - player.pos.x) >= 1) || (abs(player.oldPos.y - player.pos.y) >= 1) || spriteActive == 1)
|
||||
{
|
||||
gfx_Sprite(spaceship, player.pos.x, player.pos.y);
|
||||
player.oldPos.x = player.pos.x;
|
||||
|
Loading…
Reference in New Issue
Block a user