WIP Keyboard enhanced manager Part 2 - WIP
This commit is contained in:
parent
de542f7bd7
commit
a17ce759dd
2
TODO.txt
2
TODO.txt
|
@ -16,7 +16,7 @@ The SHMUP Todo list :
|
|||
- possibilité de transformer les trajectoires (grossissement/rétrécissement, translation et rotation)
|
||||
|
||||
Partie interaction / gameplay :
|
||||
- implémen./buildter les tirs ennemis (avec une IA minimale)
|
||||
- implémenter les tirs ennemis (avec une IA minimale)
|
||||
- implémenter les hits des tirs ennemis sur le joueur
|
||||
- implémenter les collisions avec les ennemies
|
||||
- implémenter le tir des satellites
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,14 @@
|
|||
{ "columns":9,
|
||||
"image":"tileset.png",
|
||||
"imageheight":240,
|
||||
"imagewidth":144,
|
||||
"margin":0,
|
||||
"name":"Level1_Tiles",
|
||||
"spacing":0,
|
||||
"tilecount":135,
|
||||
"tiledversion":"1.8.0",
|
||||
"tileheight":16,
|
||||
"tilewidth":16,
|
||||
"type":"tileset",
|
||||
"version":"1.8"
|
||||
}
|
Binary file not shown.
|
@ -3,15 +3,32 @@
|
|||
#include <gint/rtc.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool pressed;
|
||||
bool has_been_pressed;
|
||||
bool has_been_released;
|
||||
bool is_hold_pressed;
|
||||
bool is_hold_released;
|
||||
uint32_t lasttickevent;
|
||||
} keyinfo;
|
||||
|
||||
|
||||
keyinfo MyKeyMapper[MYKEY_LASTENUM+1];
|
||||
|
||||
|
||||
|
||||
KeyboardExtra::KeyboardExtra()
|
||||
{
|
||||
uint32_t timer = rtc_ticks();
|
||||
for(int i=0; i<=MYKEY_LASTENUM; i++)
|
||||
{
|
||||
MyKeyMapper[i].pressed_lastframe=false;
|
||||
MyKeyMapper[i].pressed_thisframe=false;
|
||||
MyKeyMapper[i].pressed=false;
|
||||
MyKeyMapper[i].has_been_pressed=false;
|
||||
MyKeyMapper[i].has_been_released=false;
|
||||
MyKeyMapper[i].is_hold_pressed=false;
|
||||
MyKeyMapper[i].is_hold_released=false;
|
||||
MyKeyMapper[i].lasttickevent=timer;
|
||||
}
|
||||
}
|
||||
|
@ -33,70 +50,124 @@ void KeyboardExtra::Update( float dt )
|
|||
{
|
||||
if(ev.key == KEY_F3) // Manage the key sequence for KEY_F3
|
||||
{
|
||||
if (ev.type == KEYEV_DOWN || ev.type == KEYEV_HOLD) // We have a keydown event detected in the pollevent queue
|
||||
if (ev.type == KEYEV_DOWN) // We have a keydown event detected in the pollevent queue
|
||||
{
|
||||
if(MyKeyMapper[MYKEY_F3].pressed_lastframe) // the key was already pressed so nothing changed
|
||||
if(MyKeyMapper[MYKEY_F3].pressed) // the key was already pressed so nothing changed
|
||||
{
|
||||
MyKeyMapper[MYKEY_F3].has_been_pressed = false;
|
||||
MyKeyMapper[MYKEY_F3].has_been_released = false;
|
||||
MyKeyMapper[MYKEY_F3].lasttickevent = timer;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_pressed = true;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_released = false;
|
||||
MyKeyMapper[MYKEY_F3].pressed = true;
|
||||
}
|
||||
else // the key was not pressed, so we can raise the keypressed event
|
||||
{
|
||||
MyKeyMapper[MYKEY_F3].has_been_pressed = true;
|
||||
MyKeyMapper[MYKEY_F3].has_been_released = false;
|
||||
MyKeyMapper[MYKEY_F3].lasttickevent = timer;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_pressed = false;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_released = false;
|
||||
MyKeyMapper[MYKEY_F3].pressed = true;
|
||||
}
|
||||
// and we update the current status of the key
|
||||
MyKeyMapper[MYKEY_F3].pressed_lastframe = MyKeyMapper[MYKEY_F3].pressed_thisframe;
|
||||
MyKeyMapper[MYKEY_F3].pressed_thisframe = true;
|
||||
}
|
||||
else if (ev.type == KEYEV_UP) // We have a keyup event detected in the pollevent queue
|
||||
{
|
||||
if(MyKeyMapper[MYKEY_F3].pressed_lastframe) // the key was pressed, so we can raise the keypressed event
|
||||
if(MyKeyMapper[MYKEY_F3].pressed) // the key was pressed, so we can raise the keypressed event
|
||||
{
|
||||
MyKeyMapper[MYKEY_F3].has_been_pressed = false;
|
||||
MyKeyMapper[MYKEY_F3].has_been_released = true;
|
||||
MyKeyMapper[MYKEY_F3].lasttickevent = timer;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_pressed = false;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_released = false;
|
||||
MyKeyMapper[MYKEY_F3].pressed = false;
|
||||
}
|
||||
else // the key was already not pressed so nothing changed
|
||||
{
|
||||
MyKeyMapper[MYKEY_F3].has_been_pressed = false;
|
||||
MyKeyMapper[MYKEY_F3].has_been_released = false;
|
||||
MyKeyMapper[MYKEY_F3].lasttickevent = timer;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_pressed = false;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_released = true;
|
||||
MyKeyMapper[MYKEY_F3].pressed = false;
|
||||
}
|
||||
// and we update the current status of the key
|
||||
MyKeyMapper[MYKEY_F3].pressed_lastframe = MyKeyMapper[MYKEY_F3].pressed_thisframe;
|
||||
MyKeyMapper[MYKEY_F3].pressed_thisframe = false;
|
||||
}
|
||||
}
|
||||
else MyKeyMapper[MYKEY_F3].pressed_lastframe = MyKeyMapper[MYKEY_F3].pressed_thisframe;
|
||||
|
||||
else
|
||||
{
|
||||
MyKeyMapper[MYKEY_F3].has_been_pressed = false;
|
||||
MyKeyMapper[MYKEY_F3].has_been_released = false;
|
||||
|
||||
if (MyKeyMapper[MYKEY_F3].pressed)
|
||||
{
|
||||
MyKeyMapper[MYKEY_F3].is_hold_pressed = true;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_released = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
MyKeyMapper[MYKEY_F3].is_hold_pressed = false;
|
||||
MyKeyMapper[MYKEY_F3].is_hold_released = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(ev.key == KEY_EXIT)
|
||||
{
|
||||
if (ev.type == KEYEV_DOWN || ev.type == KEYEV_HOLD)
|
||||
if (ev.type == KEYEV_DOWN)
|
||||
{
|
||||
MyKeyMapper[MYKEY_EXIT].pressed_lastframe = MyKeyMapper[MYKEY_EXIT].pressed_thisframe;
|
||||
MyKeyMapper[MYKEY_EXIT].pressed_thisframe = true;
|
||||
MyKeyMapper[MYKEY_EXIT].pressed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool KeyboardExtra::IsKeyPressed( int key )
|
||||
bool KeyboardExtra::IsKeyPressedEvent( int key )
|
||||
{
|
||||
return MyKeyMapper[key].has_been_pressed;
|
||||
}
|
||||
|
||||
|
||||
bool KeyboardExtra::IsKeyReleased( int key )
|
||||
bool KeyboardExtra::IsKeyReleasedEvent( int key )
|
||||
{
|
||||
return MyKeyMapper[key].has_been_released;
|
||||
}
|
||||
|
||||
|
||||
bool KeyboardExtra::IsKeyOn( int key )
|
||||
bool KeyboardExtra::IsKeyPressed( int key )
|
||||
{
|
||||
return MyKeyMapper[key].pressed_thisframe;
|
||||
return MyKeyMapper[key].pressed;
|
||||
}
|
||||
|
||||
|
||||
bool KeyboardExtra::IsKeyReleased( int key )
|
||||
{
|
||||
return (!MyKeyMapper[key].pressed);
|
||||
}
|
||||
|
||||
|
||||
uint32_t KeyboardExtra::IsKeyHoldPressed( int key )
|
||||
{
|
||||
if (MyKeyMapper[key].is_hold_pressed)
|
||||
{
|
||||
uint32_t a = rtc_ticks();
|
||||
return (uint32_t) (a - MyKeyMapper[key].lasttickevent);
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
uint32_t KeyboardExtra::IsKeyHoldReleased( int key )
|
||||
{
|
||||
if (MyKeyMapper[key].is_hold_released)
|
||||
{
|
||||
uint32_t a = rtc_ticks();
|
||||
return (uint32_t) (a - MyKeyMapper[key].lasttickevent);
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
uint32_t KeyboardExtra::GetLastTickKeyEvent( int key )
|
||||
{
|
||||
return MyKeyMapper[key].lasttickevent;
|
||||
}
|
|
@ -3,14 +3,6 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool pressed_lastframe;
|
||||
bool pressed_thisframe;
|
||||
bool has_been_pressed;
|
||||
bool has_been_released;
|
||||
uint32_t lasttickevent;
|
||||
} keyinfo;
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -40,8 +32,6 @@ enum
|
|||
};
|
||||
|
||||
|
||||
static keyinfo MyKeyMapper[MYKEY_LASTENUM+1];
|
||||
|
||||
|
||||
class KeyboardExtra
|
||||
{
|
||||
|
@ -50,9 +40,13 @@ class KeyboardExtra
|
|||
~KeyboardExtra();
|
||||
|
||||
void Update( float dt );
|
||||
bool IsKeyPressedEvent( int key );
|
||||
bool IsKeyReleasedEvent( int key );
|
||||
bool IsKeyPressed( int key );
|
||||
bool IsKeyReleased( int key );
|
||||
bool IsKeyOn( int key );
|
||||
uint32_t IsKeyHoldPressed( int key );
|
||||
uint32_t IsKeyHoldReleased( int key );
|
||||
uint32_t GetLastTickKeyEvent( int key );
|
||||
};
|
||||
|
||||
|
||||
|
|
60
src/main.cpp
60
src/main.cpp
|
@ -215,8 +215,11 @@ static void render( void )
|
|||
#if(BIAS)
|
||||
if (texttodraw>=1) Azur_draw_text(1,01, "FPS = %.0f", (float) (1000000.0f / elapsedTime) );
|
||||
|
||||
if (texttodraw>=1) Azur_draw_text(1,11, "Render = %.0f mc secs", (float) time_render );
|
||||
|
||||
if (texttodraw>=1) Azur_draw_text(1,11, "Render = %.0f mc secs", (float) time_render / 1000.0f );
|
||||
if (texttodraw>=1) Azur_draw_text(1,21, "Hold Down : %d ", MyKeyboard.IsKeyHoldPressed(MYKEY_F3));
|
||||
if (texttodraw>=1) Azur_draw_text(1,31, "Hold Up : %d ", MyKeyboard.IsKeyHoldReleased(MYKEY_F3));
|
||||
if (texttodraw>=1) Azur_draw_text(1,41, "Last Tick Event : %d ", MyKeyboard.GetLastTickKeyEvent(MYKEY_F3));
|
||||
|
||||
/* if (texttodraw>=1) Azur_draw_text(1,11, "Part.= %d - Bull.= %d", MyParticles.size(), MyPlayerBullets.size() );
|
||||
if (texttodraw>=1 && !MyEnemies.empty()) Azur_draw_text(1,21, "Ennmy Life= %d", MyEnemies[0]->life );
|
||||
if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.0f mc secs", (float) time_update );
|
||||
|
@ -255,14 +258,15 @@ static void get_inputs( float dt )
|
|||
if (MyPlayer->Shoot_OK(tempshoot, 1)) Create_Player_Shoot(1);
|
||||
}
|
||||
//if(keydown(KEY_F3))
|
||||
if(MyKeyboard.IsKeyPressed(MYKEY_F3))
|
||||
if(MyKeyboard.IsKeyPressedEvent(MYKEY_F3))
|
||||
{
|
||||
if (MyPlayer->Shoot_OK(tempshoot, 2)) Create_Player_Shoot(2);
|
||||
}
|
||||
|
||||
// if (MyKeyboard.IsKeyPressed(MYKEY_F3)) color=C_RED;
|
||||
// if (MyKeyboard.IsKeyReleased(MYKEY_F3)) color=C_GREEN;
|
||||
|
||||
if (MyKeyboard.IsKeyOn(MYKEY_EXIT)) {exitToOS = true; };
|
||||
|
||||
if (MyKeyboard.IsKeyPressed(MYKEY_EXIT)) {exitToOS = true; };
|
||||
|
||||
if(keydown(KEY_EXIT)) {exitToOS = true; };
|
||||
|
||||
|
@ -275,45 +279,22 @@ static void get_inputs( float dt )
|
|||
#endif
|
||||
|
||||
if(keydown(KEY_SHIFT) && keydown(KEY_F1)) {texttodraw=0;}
|
||||
|
||||
if(keydown(KEY_SHIFT) && keydown(KEY_F2)) {texttodraw=1;}
|
||||
|
||||
if(keydown(KEY_SHIFT) && keydown(KEY_F3)) {texttodraw=2;}
|
||||
|
||||
if(keydown(KEY_SHIFT) && keydown(KEY_F4)) {texttodraw=3;}
|
||||
|
||||
if(keydown(KEY_SHIFT) && keydown(KEY_F6))
|
||||
{
|
||||
azrp_starfield_close( );
|
||||
azrp_starfield_init( 100 );
|
||||
}
|
||||
|
||||
// if(keydown(KEY_F5)) drawback = !drawback;
|
||||
// if(keydown(KEY_F6)) drawstars = !drawstars;
|
||||
|
||||
if(keydown(KEY_F5)) drawback = !drawback;
|
||||
|
||||
if(keydown(KEY_F6)) drawstars = !drawstars;
|
||||
|
||||
|
||||
if(keydown(KEY_LEFT))
|
||||
{
|
||||
MyPlayer->Go_Left( dt );
|
||||
}
|
||||
if(keydown(KEY_RIGHT))
|
||||
{
|
||||
MyPlayer->Go_Right( dt );
|
||||
}
|
||||
if(keydown(KEY_UP))
|
||||
{
|
||||
MyPlayer->Go_Up( dt );
|
||||
}
|
||||
if(keydown(KEY_DOWN))
|
||||
{
|
||||
MyPlayer->Go_Down( dt );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(keydown(KEY_LEFT)) { MyPlayer->Go_Left( dt ); }
|
||||
if(keydown(KEY_RIGHT)) { MyPlayer->Go_Right( dt ); }
|
||||
if(keydown(KEY_UP)) { MyPlayer->Go_Up( dt ); }
|
||||
if(keydown(KEY_DOWN)) { MyPlayer->Go_Down( dt ); }
|
||||
|
||||
}
|
||||
|
||||
|
@ -446,17 +427,6 @@ int main(void)
|
|||
prof_leave(perf_render);
|
||||
time_render = prof_time(perf_render);
|
||||
|
||||
#if(NOBIAS)
|
||||
dclear(C_BLACK);
|
||||
dprint(1,01, C_WHITE, "Update = %.0f mc secs", (float) time_update );
|
||||
dprint(1,11, C_WHITE, "Render = %.0f mc secs", (float) time_render );
|
||||
dprint(1,21, C_WHITE, ">Total = %.3f ml secs", (float) elapsedTime / 1000.0f );
|
||||
dprint(1,31, C_WHITE, ">Total = %.0f", (float) elapsedTime );
|
||||
dprint(1,41, C_WHITE, " FPS = %.0f", (float) (1000000.0f / elapsedTime) );
|
||||
dprint(1,51, C_WHITE, "Parts = %d", MyParticles.size() );
|
||||
dupdate();
|
||||
#endif
|
||||
|
||||
elapsedTime = ((float) (time_update+time_render));
|
||||
|
||||
#if(DEBUG_MODE)
|
||||
|
|
Loading…
Reference in New Issue