Browse Source

more…

master
flo 2 years ago
parent
commit
b892a1341d
15 changed files with 146 additions and 67 deletions
  1. BIN
      img/firearm.bmp
  2. BIN
      img/missile.bmp
  3. BIN
      img/weapons.bmp
  4. 29
    10
      include/wings.h
  5. BIN
      obj/cloud.bmp.o
  6. BIN
      obj/firearm.bmp.o
  7. BIN
      obj/img_menu.bmp.o
  8. BIN
      obj/maths.c.o
  9. BIN
      obj/plane.bmp.o
  10. BIN
      obj/weapons.bmp.o
  11. BIN
      obj/wings.c.o
  12. 117
    57
      src/wings.c
  13. BIN
      wings.bin
  14. BIN
      wings.elf
  15. BIN
      wings.g1a

BIN
img/firearm.bmp View File


BIN
img/missile.bmp View File


BIN
img/weapons.bmp View File


+ 29
- 10
include/wings.h View File

@@ -1,7 +1,13 @@
#ifndef WINGS
#define WINGS

#define MAX_MISSILES 4
#define MAX_CHARGE 40
#define MAX_PLANES 7
#define MAX_CLOUDS 15
#define MAX_WEAPON 3

#define MAP_SIZE_X 256
#define MAP_SIZE_Y 256

// direction management
typedef struct Direction
@@ -10,15 +16,15 @@ typedef struct Direction
char dy;
} Direction;

// missiles management
typedef struct Missile
// Arms management
typedef struct Firearm
{
short x;
short y;
Direction dir;
char useful;
// short distance; // distance between the plane and the missile
unsigned char type;
} Missile;
} Firearm;

// plane management
typedef struct Plane
@@ -35,9 +41,12 @@ typedef struct Plane
*/

unsigned char life;
unsigned char bullets;
unsigned char bullets_nb;
unsigned char bullets_type;
// 0 : missiles
// 1 : lightning

Missile missiles[MAX_MISSILES];
Firearm firearm[MAX_CHARGE];
// align
} Plane;

@@ -47,15 +56,25 @@ typedef struct Cloud
short y;
} Cloud;

typedef struct Dir_t
//for timer callback
typedef struct FTCb
{
Direction map_dir;
Direction dir_requested;
} Dir_t;
unsigned char max_charge;
} FTCb;

typedef struct Weapon
{
short x;
short y;
char dy;
char type;
} Weapon;

int menu(void);
void init(void);
void update_frame(Dir_t *way);
void update_frame(FTCb *info);
int game(void);

#endif

BIN
obj/cloud.bmp.o View File


BIN
obj/firearm.bmp.o View File


BIN
obj/img_menu.bmp.o View File


BIN
obj/maths.c.o View File


BIN
obj/plane.bmp.o View File


BIN
obj/weapons.bmp.o View File


BIN
obj/wings.c.o View File


+ 117
- 57
src/wings.c View File

@@ -8,22 +8,19 @@
#include "stdio.h"
#include "stdlib.h"

#define MAP_SIZE_X 256
#define MAP_SIZE_Y 256

#define MAX_PLANES 2
#define MAX_CLOUDS 15

Plane planes[MAX_PLANES]; // number of planes in the map (with us)
//others planes are controlled by the AI

Cloud clouds[MAX_CLOUDS]; //number of clouds in this beautifull sky
// generated by the IA

Weapon weapon[MAX_WEAPON]; // numbre of weapon changing in the sky (fall)

extern image_t plane;
extern image_t img_menu;
extern image_t cloud;
extern image_t missile;
extern image_t firearm;
extern image_t weapons;

int main()
{
@@ -37,17 +34,19 @@ void init()

for(i = 0; i < MAX_PLANES; i++)
{
planes[i].x = 56 + 16 * i;
planes[i].y = 24 + i;
planes[i].x = 56;
planes[i].y = 24;
planes[i].dir.dx = 0;
planes[i].dir.dy = 0;
planes[i].life = 100;
planes[i].bullets = 6;
planes[i].dir.dx = i;
planes[i].dir.dy = i;
planes[i].bullets_nb = MAX_CHARGE;
planes[i].bullets_type = 0;

for(j = 0; j < MAX_MISSILES; j++)
for(j = 0; j < MAX_CHARGE; j++)
{
planes[i].missiles[j].dir = planes[i].dir;
planes[i].missiles[j].type = 0;
planes[i].firearm[j].dir = planes[i].dir;
planes[i].firearm[j].dir.dx = 0;
planes[i].firearm[j].dir.dy = 0;
}
}

@@ -56,6 +55,14 @@ void init()
clouds[i].x = 10 + 16*i;
clouds[i].y = 10 + 16*i;
}

for(i = 0; i < MAX_WEAPON; i++)
{
weapon[i].x = 14 * i + 10;
weapon[i].y = 0;
weapon[i].dy = -1;
weapon[i].type = i%2;
}
}

int menu()
@@ -87,45 +94,65 @@ int menu()
}
}

void update_frame(Dir_t *way)
void update_frame(FTCb *info)
{
static unsigned char i,j;

dclear();

dprint(1, 1, "s:%d l:%d", planes[0].bullets, planes[0].life);
dprint(1, 10, "(%d,%d)", way->map_dir.dx, way->map_dir.dy);
dprint(1, 1, "s:%d l:%d", planes[0].bullets_nb, planes[0].life);
dprint(1, 10, "(%d,%d) (%d,%d)", info->map_dir.dx, info->map_dir.dy, planes[0].x, planes[0].y);
//dprint(1,10, "(x,y)(%d,%d)", planes[1].x + decalx, planes[1].y + decaly);

if(way->dir_requested.dx != 0 || way->dir_requested.dy != 0)
if(info->dir_requested.dx != 0 || info->dir_requested.dy != 0)
{
way->map_dir = way->dir_requested;
planes[0].dir = way->dir_requested;
info->map_dir = info->dir_requested;
planes[0].dir = info->dir_requested;
}

for(i = 0; i < MAX_CLOUDS; i++)
{
clouds[i].x += way->map_dir.dx;
clouds[i].y += way->map_dir.dy;
clouds[i].x += 2 * info->map_dir.dx;
clouds[i].y += 2 * info->map_dir.dy;

dimage(clouds[i].x, clouds[i].y, &cloud);
}

for(i = 0; i < MAX_WEAPON; i++)
{
weapon[i].y += 2 * info->map_dir.dy - weapon[i].dy;
weapon[i].x += 2 * info->map_dir.dx;

if(weapon[i].y > MAP_SIZE_Y)
{
weapon[i].y = 0;
}

dimage_part(weapon[i].x, weapon[i].y, &weapons, 10 * weapon[i].type, 0, 10, 10);
}

for (i = 0; i < MAX_PLANES; i++)
{
if(i > 0)
{
planes[i].x += way->map_dir.dx - planes[i].dir.dx;
planes[i].y += way->map_dir.dy - planes[i].dir.dy;
planes[i].x += 2 * info->map_dir.dx - 3 * planes[i].dir.dx;
planes[i].y += 2 * info->map_dir.dy - 3 * planes[i].dir.dy;
}

dimage_part(planes[i].x, planes[i].y, &plane, 16*(1 - planes[i].dir.dx), 16 * (1 - planes[i].dir.dy), 16, 16);
dimage_part(planes[i].x, planes[i].y, &plane, 16 * (1 - planes[i].dir.dx), 16 * (1 - planes[i].dir.dy), 16, 16);

for(j = 0; j < MAX_MISSILES; j++)
for(j = 0; j < info->max_charge; j++)
{
planes[i].missiles[j].x += way->map_dir.dx - 2 * planes[i].missiles[j].dir.dx;
planes[i].missiles[j].y += way->map_dir.dy - 2 * planes[i].missiles[j].dir.dy;
planes[i].firearm[j].x += 2 * info->map_dir.dx - 4 * planes[i].firearm[j].dir.dx;
planes[i].firearm[j].y += 2 * info->map_dir.dy - 4 * planes[i].firearm[j].dir.dy;

dimage_part(planes[i].missiles[j].x, planes[i].missiles[j].y ,&missile, 8 * (1 - planes[i].missiles[j].dir.dx), 8 * (1 - planes[i].missiles[j].dir.dy), 8, 8);
// if one bullet is too far, delete it
if(abs(planes[i].firearm[j].x - planes[i].x) > 72 || abs(planes[i].firearm[j].y - planes[i].y) > 72)
{
info->max_charge--;
}

dimage_part(planes[i].firearm[j].x, planes[i].firearm[j].y ,&firearm, 8 * (1 - planes[i].firearm[j].dir.dx) + 24 * planes[i].bullets_type, 8 * (1 - planes[i].firearm[j].dir.dy), 8, 8);
}
}
dupdate();
@@ -133,22 +160,23 @@ void update_frame(Dir_t *way)

int game()
{
unsigned char fire = 0, j = 0; // fire disable
unsigned char i = 0; // fire disable

//direction for the map
Dir_t way;
FTCb info;

init();

timer_t *timer = NULL;
timer = timer_create(50, 0);
timer_attach(timer, update_frame, &way);
timer = timer_create(40, 0);
timer_attach(timer, update_frame, &info);
timer_start(timer);

event_t events;

way.map_dir.dx = way.dir_requested.dx = 0;
way.map_dir.dy = way.dir_requested.dy = 0;
// variable initialisation
info.map_dir.dx = info.dir_requested.dx = 0;
info.map_dir.dy = info.dir_requested.dy = 0;
info.max_charge = 0;

while(1)
{
@@ -160,34 +188,66 @@ int game()
{
case KEY_UP :
{
way.dir_requested.dy += 3 - events.type;
info.dir_requested.dy += 3 - events.type;
break;
}
case KEY_DOWN :
{
way.dir_requested.dy -= 3 - events.type;
info.dir_requested.dy -= 3 - events.type;
break;
}
case KEY_LEFT :
{
way.dir_requested.dx += 3 - events.type;
info.dir_requested.dx += 3 - events.type;
break;
}
case KEY_RIGHT :
{
way.dir_requested.dx -= 3 - events.type;
info.dir_requested.dx -= 3 - events.type;
break;
}

case KEY_SHIFT :
{

fire = 1;
/*if(planes[0].bullets > 0)
//maybe (if(event.key.release))
switch(planes[0].bullets_type)
{
planes[0].bullets = planes[0].bullets - 1;
fire = 1;
}*/
planes[0].bullets_nb = planes[0].bullets_nb - 1;
case 0 :
{
if(planes[0].bullets_nb > 0 && events.type == event_key_release)
{
planes[0].firearm[info.max_charge].dir = planes[0].dir;
planes[0].firearm[info.max_charge].x = 60 - 6 * planes[0].firearm[info.max_charge].dir.dx;
planes[0].firearm[info.max_charge].y = 28 - 6 * planes[0].firearm[info.max_charge].dir.dy;
info.max_charge = (info.max_charge < MAX_CHARGE - 1 ? info.max_charge + 1 : 0);
}
break;
}
case 1 :
{
if(events.type == event_key_release)
{
for(i = 0; i < ; i++)
{
planes[0].firearm[i].dir = planes[0].dir;
planes[0].firearm[i].x = 60 - 8 * planes[0].firearm[i].dir.dx * i;
planes[0].firearm[i].y = 28 - 8 * planes[0].firearm[i].dir.dy * i;
}
}
/*else if(events.type == event_key_repeat)
{
for(j = 0; j< MAX_CHARGE; j++)
{
planes[0].firearm[j].dir.dx = 0;
planes[0].firearm[j].dir.dy = 0;
planes[0].firearm[j].x = -256;
planes[0].firearm[j].y = -256;
}
}*/
break;
}
}
break; // fire enable
}

@@ -196,17 +256,17 @@ int game()
timer_destroy(timer); //destroy the virtual timer
return 1; // good bye, see you soon
}
case KEY_1 :
{
planes[0].bullets_type = 1;
break;
}
case KEY_0 :
{
planes[0].bullets_type = 0;
break;
}
}
}

if(fire)
{
planes[0].missiles[0].dir = planes[0].dir;

planes[0].missiles[0].x = 60 - 6 * planes[0].missiles[0].dir.dx;
planes[0].missiles[0].y = 28 - 6 * planes[0].missiles[0].dir.dy;

fire = 0;
}
}
}

BIN
wings.bin View File


BIN
wings.elf View File


BIN
wings.g1a View File


Loading…
Cancel
Save