From 276bd46e2bb2b75d41c378a295b8c89b226fd2eb Mon Sep 17 00:00:00 2001 From: stevenhowes <38082088+stevenhowes@users.noreply.github.com> Date: Sat, 20 Mar 2021 23:50:36 +0000 Subject: [PATCH] Projectile spawn and render --- !RunImage,ff8 | Bin 10772 -> 11592 bytes c/CTheEscape | 115 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 112 insertions(+), 3 deletions(-) diff --git a/!RunImage,ff8 b/!RunImage,ff8 index f7b82fab08041da3dbf2a973b55dbab71244070e..2b4abf54a9639826a979ad3d18a9201da8254124 100644 GIT binary patch delta 4257 zcmaJ^4RBP|6+Z9ne^`>2WJ3ahyxk;)h(Q(#l{!>5K_do)4GkGZ4GAOy)<6aVDy6eY zOaKc=;!XHbEKf%*YS18(TCfcA<4}qY<0wY0zaHxe~U6#wfO(U~6!H7;A(v~tBHN{o|f z`HH4hE1`E1#fBf%bftg7fVFo{B!%wR2V8WR0-9kZ&4@ZE`nkF-B4Pe5=6}ar#{3fI zA7gI8{431QVJ`3&F;91bPumuG79)8z9rBQV%C8xcq8V8bo`v$M>&m!JhAtJdQvuER zEA&qe(F_Bm~lM**6i1e!fVGb{l00<;#osY7&D z=w5>E7T7yrzXF)zB#g(O*j5dgPt8Q?fGJ4A*!)_^5ZUekDDN)Ks0JW62{2e2+n}F< zKr+6j3Yd%}%wz--J~jaJfQcyw#+8K0Gn4rpFl{F0c3{X^aIF&cK}Ssh^_ifX0s4WZ zTQev82GR?rbRwi*gEwnfuY-HBR*NC~8FXK=3TtM`z2L@z8+nsv*v4o^x1FNJIEOuu zUlrEmH@#@Z?dyi}tZ{gOg=A zN?o7XC|U^fB6h!Ho}6K4uR6-7?t)ON*$}Z&mGMq2cIeV8_YU;GLe%vd(bC$6`bBlC zY9C(IxN7Bt^-G$TKUBXO{UV3?Y?;+QXQD&QsoBFHsZe>FR2L>`L)fEqa4ARAOLBU3 zbe0s^+ri}`O)mw}HJ#`P9h{`@FFQmAfi`rVO5-bJfUg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qu5777jA}v4WUr57tdnI-4mhU%W&>iv53+yIN`) z3f>1f4%q-)!8)#;2#s#4d9p!#pih30+oQh7E0Jdv;?2Oi@56U}20A~Rs45KX0gwv7 ziY2n4cb`G`W{7t}6F-3jBPC+Pi{-DtnWT?D05+-L2!-B{hi?T6FT#W?aQe5iiR?nT zzjq*iM!sYb9|V8uWtBOV^3C3X!#PW0CZSQsxLk0QU7J}hU+NoJ=&Y3Gt9|UbycZ@3 z&e`w8f9EZHjvz!uHyfSZEYJIBpdr6fTIuT{(hd<794Gqj2_hL27rLMdeeY@fUxMGx zoe@k_A+X7x(8FIEun#B&S`2d(nAovGYwnp>iPk}?A>t>Z_CR_e{fC&pu#AlrPGdzy nc}y>Kv!54vTw7iy+6LJH`6*;4#0%LC*$ZihbV9lzFG2nTMVeR3 diff --git a/c/CTheEscape b/c/CTheEscape index f516371..72bd757 100644 --- a/c/CTheEscape +++ b/c/CTheEscape @@ -22,9 +22,10 @@ extern int current_element; #define PLAYER_X_SPEED 10 #define MAX_NPCS 5 #define MAX_STARS 49 +#define MAX_PROJECTILES 10 -enum sprite_e{player_ship, durno_ship, durno_ship2, player_shipl,player_shipr,explode_shp1,explode_shp2,explode_shp3,explode_shp4}; -char *sprites[] = {"player_ship","durno_ship","durno_ship2","player_shipl","player_shipr","explode_shp1","explode_shp2","explode_shp3","explode_shp4"}; +enum sprite_e{player_ship, durno_ship, durno_ship2, player_shipl,player_shipr,explode_shp1,explode_shp2,explode_shp3,explode_shp4,photon1,photon2}; +char *sprites[] = {"player_ship","durno_ship","durno_ship2","player_shipl","player_shipr","explode_shp1","explode_shp2","explode_shp3","explode_shp4","photon1","photon2"}; char hudbuffer[63]; @@ -62,7 +63,6 @@ struct Star_s { unsigned char length; }; - struct Player_s { struct EntityLocation_s location; enum sprite_e idlesprite; @@ -78,8 +78,19 @@ struct Player_s { struct EntityLocation_s phaser2; }; +struct Projectile_s { + struct EntityLocation_s location; + enum sprite_e sprite; + struct EntityLocation_s velocity; + int collidable; + int nextframe; + short int active; + int damage; +}; + struct Star_s Stars[MAX_STARS]; struct NPC_s NPCS[MAX_NPCS]; +struct Projectile_s Projectiles[MAX_PROJECTILES]; struct Player_s Player; @@ -242,6 +253,18 @@ void game_draw_npcs() } } +void game_draw_projectiles() +{ + int i; + for(i = 0; i < MAX_PROJECTILES; i++) + { + if(Projectiles[i].active == 0) + continue; + + draw_sprite(sprites[Projectiles[i].sprite], Projectiles[i].location.X,Projectiles[i].location.Y); + } +} + void game_draw_stars() { unsigned char i; @@ -408,6 +431,15 @@ void game_draw_debugmenu() } } + if(0) + { + font_colour(colours[debuggreen],colours[lcars_black],font[sys_12_8]); + for(i = 0; i < MAX_PROJECTILES; i++) + { + sprintf(hudbuffer,"Projectiles[%i] %i,%i %i,%i %i",i,Projectiles[i].velocity.X,Projectiles[i].velocity.Y,Projectiles[i].location.X,Projectiles[i].location.Y,Projectiles[i].active); + draw_text(hudbuffer,DISPLAY_X-800,DISPLAY_Y-60-(i * 20),font[sys_12_8]); + } + } } void game_collider_tick() @@ -470,6 +502,77 @@ int game_hitbox_collide(int x1, int y1, int w1, int h1, int x2, int y2, int w2, return 0; } +void game_projectiles_tick() +{ + int i; + for(i = 0; i < MAX_PROJECTILES; i++) + { + if(!Projectiles[i].active) + continue; + + if(tick > Projectiles[i].nextframe) + { + if((Projectiles[i].sprite >= photon1) && (Projectiles[i].sprite <= photon2)) + { + Projectiles[i].sprite++; + if(Projectiles[i].sprite > photon2) + Projectiles[i].sprite = photon1; + } + Projectiles[i].nextframe = tick + 10; + } + + + Projectiles[i].location.Y -= (tick - lasttick) * Projectiles[i].velocity.Y; + Projectiles[i].location.X -= (tick - lasttick) * Projectiles[i].velocity.X; + + if((Projectiles[i].location.Y) <= 0) + { + Projectiles[i].active = 0; + } + } +} + +void game_spawn_projectile(int id,int Px,int Py, int Vx,int Vy,enum sprite_e sprite, int damage) +{ + int i; + + if(id < 0) + { + for(i = 0; i < MAX_PROJECTILES; i++) + { + if(Projectiles[i].active == 0) + id = i; + } + } + + // If no velocity X specified we're targetting the player + if(Vx == 0) + { + int Xdistance = abs(Player.location.X - Px); + int Ydistance = abs(Player.location.Y - Py); + int distance = sqrt((Xdistance^2) + (Ydistance^2)); + Vx = Xdistance / (distance / 10); + Vy = Ydistance / (distance / 10); + if(Player.location.X > Px) + Vx = 0 - Vx; + } + + //If no free IDs then we go without + if(id >= 0) + { + Projectiles[id].location.X = Px; + Projectiles[id].location.Y = Py; + Projectiles[id].velocity.X = Vx; + Projectiles[id].velocity.Y = Vy; + Projectiles[id].active = 1; + Projectiles[id].sprite = sprite; + Projectiles[id].nextframe = tick + 10; + Projectiles[id].damage = damage; + Projectiles[id].collidable = 1; + } + +} + void game_input_tick() { if(debugs[dbbase]) @@ -489,6 +592,9 @@ void game_input_tick() // 5 if(input_readkey(19)) debugs[dbnpcs] = 1; + // W + if(input_readkey(33)) + game_spawn_projectile(-1,DISPLAY_X/2,DISPLAY_Y - 200,0,2,photon1,50); } if(debugs[dbinput]) @@ -594,10 +700,13 @@ void game_tick() game_tick_player(); game_tick_npcs(); game_collider_tick(); + game_projectiles_tick(); game_draw_stars(); game_draw_player(); game_draw_npcs(); + game_draw_projectiles(); + game_draw_hud(); game_draw_debugmenu(); }