Skip to content

Commit

Permalink
Added ingame Weapon menu button for touchscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
theZiz committed Apr 27, 2017
1 parent 1a90be1 commit dd3569d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 22 deletions.
1 change: 0 additions & 1 deletion ToDo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
* Mouse support
* In game ;)
* Button for Weapon choice (weapon itself?)
* Weapon choice touchpad sensitive
* left button moves hare (arrow left and right replacement)
* right button sets shooting direction (arrow up and down replacement)
14 changes: 6 additions & 8 deletions about.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ int help_was_pressed;
void help_draw(void)
{
spClearTarget(LL_BG);
int B0 = spMax(spGetSizeFactor()>>17,1);
int B1 = spMax(spGetSizeFactor()>>16,1);
int B2 = spMax(spGetSizeFactor()>>15,1);
int B4 = spMax(spGetSizeFactor()>>14,1);
const int B1 = spMax(spGetSizeFactor()>>16,1);
const int B2 = spMax(spGetSizeFactor()>>15,1);
spFontDrawMiddle( spGetWindowSurface()->w/2, 2, 0, "How to Play", help_font );
int h = spGetWindowSurface()->h - 4 - 4*help_font->maxheight;
spFontDrawTextBlock(left,2+spGetWindowSurface()->w/6,2*help_font->maxheight+2, 0,help_block,h,help_scroll,help_font);
Expand All @@ -64,7 +62,7 @@ void help_draw(void)
help_button[2].y = spGetWindowSurface()->h-2-2*help_font->maxheight;
int width = help_button[2].w;
int height = help_font->maxheight;
draw_edgy_rectangle(help_button[2].x,help_button[2].y,&width,&height,B0,B1,B2,B4);
draw_edgy_rectangle(help_button[2].x,help_button[2].y,&width,&height,B1,B2);
spFontDraw( help_button[2].x, help_button[2].y, 0, button_text, help_font );
}
else
Expand All @@ -83,7 +81,7 @@ void help_draw(void)
help_button[1].y = 2+ help_font->maxheight;
int width = help_button[1].w;
int height = help_font->maxheight;
draw_edgy_rectangle(help_button[1].x,help_button[1].y,&width,&height,B0,B1,B2,B4);
draw_edgy_rectangle(help_button[1].x,help_button[1].y,&width,&height,B1,B2);
spFontDraw( help_button[1].x, help_button[1].y, 0, button_text, help_font );
}
else
Expand All @@ -97,10 +95,10 @@ void help_draw(void)
help_button[0].w = spFontWidth( button_text, help_font );
help_button[0].h = help_font->maxheight;
help_button[0].x = spGetWindowSurface()->w/2 - help_button[0].w/2;
help_button[0].y = spGetWindowSurface()->h-B4-help_font->maxheight;
help_button[0].y = spGetWindowSurface()->h-B2*2-help_font->maxheight;
int width = help_button[0].w;
int height = help_font->maxheight;
draw_edgy_rectangle(help_button[0].x,help_button[0].y,&width,&height,B0,B1,B2,B4);
draw_edgy_rectangle(help_button[0].x,help_button[0].y,&width,&height,B1,B2);
spFontDraw( help_button[0].x, help_button[0].y, 0, button_text, help_font );
spFlip();
}
Expand Down
60 changes: 58 additions & 2 deletions hase.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ spNetIRCMessagePointer before_showing;
SDL_Surface* screen;
SDL_Surface* tomato;

spFontPointer help_font;
struct
{
int x;
int y;
int w;
int h;
int pressed;
} weapon_button;


void ( *hase_resize )( Uint16 w, Uint16 h );

void loadInformation(char* information)
Expand Down Expand Up @@ -542,7 +553,6 @@ void draw(void)

y += font->maxheight*3/4+(spGetSizeFactor()*2 >> SP_ACCURACY);
}

spFontDrawRight( screen->w-1 - player[active_player]->weapon_points * tomato->w, screen->h-1-font->maxheight, 0,
player[active_player]->weapon_points > 0 ? "Action points:" : "Action points: None", font );
int i;
Expand All @@ -552,7 +562,18 @@ void draw(void)
{
char number[32];
int w_nr = weapon_pos[player[active_player]->activeHare->wp_y][player[active_player]->activeHare->wp_x];
spFontDrawRight( screen->w-1, screen->h-1-font->maxheight*2, 0, weapon_name[w_nr], font );
int B1 = spMax(spGetSizeFactor()>>16,1);
int B2 = spMax(spGetSizeFactor()>>15,1);
weapon_button.w = spFontWidth( weapon_name[w_nr], font );
weapon_button.h = font->maxheight;
weapon_button.x = screen->w-1 - weapon_button.w;
weapon_button.y = screen->h-1-font->maxheight*2;
int width = weapon_button.w;
int height = font->maxheight;
spSetPattern8(153,60,102,195,153,60,102,195);
draw_edgy_rectangle(weapon_button.x,weapon_button.y,&width,&height,B1,B2);
spDeactivatePattern();
spFontDraw( weapon_button.x, weapon_button.y, 0, weapon_name[w_nr], font );
int bar_w = spFontWidth(" 88.8 % ",font);
int bar_s;
if (w_nr == WP_BUILD_SML || w_nr == WP_BUILD_MID || w_nr == WP_BUILD_BIG ||
Expand All @@ -575,6 +596,14 @@ void draw(void)
spDeactivatePattern();
spFontDrawMiddle( screen->w-1-bar_w/2, screen->h-1-3*font->maxheight, 0, number, font );
}
else
{
weapon_button.x = -1;
weapon_button.y = -1;
weapon_button.w = -1;
weapon_button.h = -1;
}

if (ragnarok_counter && (hase_game->options.bytewise.ragnarok_border >> 4) < 7)
{
sprintf(buffer,"RAGNARÖK %i",turn_count - (hase_game->options.bytewise.ragnarok_border >> 4)*5 + 1);
Expand Down Expand Up @@ -1090,6 +1119,28 @@ int calc(Uint32 steps)
spSoundPause(0,-1);
spUpdateSprite(spActiveSprite(targeting),steps);
spParticleUpdate(&particles,steps);

if ( spGetInput()->touchscreen.pressed )
{
int mx = spGetInput()->touchscreen.x;
int my = spGetInput()->touchscreen.y;
if ( weapon_button.x + weapon_button.w >= mx &&
weapon_button.x <= mx &&
weapon_button.y + weapon_button.h >= my &&
weapon_button.y <= my )
{
weapon_button.pressed = 1;
spMapSetByID( MAP_WEAPON, 1 );
spGetInput()->touchscreen.pressed = 0;
}
}
else
if (weapon_button.pressed)
{
spMapSetByID( MAP_WEAPON, 0 );
weapon_button.pressed = 0;
}

for (i = 0; i < steps; i++)
{
//Camera
Expand Down Expand Up @@ -1799,6 +1850,11 @@ void update_map()

int hase(void ( *resize )( Uint16 w, Uint16 h ),pGame game,pPlayer me_list)
{
weapon_button.x = -1;
weapon_button.y = -1;
weapon_button.w = -1;
weapon_button.h = -1;
weapon_button.pressed = 0;
input_ok_on = 0;
time_t t = time(NULL);
struct tm tm = *localtime(&t);
Expand Down
3 changes: 1 addition & 2 deletions lobbyGame.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,12 @@ void lobby_draw_buttons(window_text_positon position, int x, int y, char const *
text[i] = 0;
if (!in_button)
{
int B0 = spMax(spGetSizeFactor()>>17,1);
int B1 = spMax(spGetSizeFactor()>>16,1);
int B2 = spMax(spGetSizeFactor()>>15,1);
int B4 = spMax(spGetSizeFactor()>>14,1);
width = spFontWidth( text, font ) + B4;
int height = font->maxheight;
draw_edgy_rectangle(x,y,&width,&height,B0,B1,B2,B4);
draw_edgy_rectangle(x,y,&width,&height,B1,B2);
int j = 0;
for (; text[j] && text[j] != '}' && text[j] != ']';j++);
if (text[j])
Expand Down
13 changes: 5 additions & 8 deletions window.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pWindowElement add_window_element(pWindow window,int type,int reference)

pWindow recent_window = NULL;

void draw_edgy_rectangle(int x, int y, int * width, int * height, int B0, int B1, int B2,int B4)
void draw_edgy_rectangle(int x, int y, int * width, int * height, int B1, int B2)
{
*width += 2*B1;
int Y;
Expand Down Expand Up @@ -180,13 +180,11 @@ static void window_draw_buttons(window_text_positon position, int x, int y, char
text[i] = 0;
if (!in_button)
{
int B0 = spMax(spGetSizeFactor()>>17,1);
int B1 = spMax(spGetSizeFactor()>>16,1);
int B2 = spMax(spGetSizeFactor()>>15,1);
int B4 = spMax(spGetSizeFactor()>>14,1);
const int B1 = spMax(spGetSizeFactor()>>16,1);
const int B2 = spMax(spGetSizeFactor()>>15,1);
width = spFontWidth( text, recent_window->font );
int height = recent_window->font->maxheight;
draw_edgy_rectangle(x,y,&width,&height,B0,B1,B2,B4);
draw_edgy_rectangle(x,y,&width,&height,B1,B2);
int j = 0;
for (; text[j] && text[j] != '}' && text[j] != ']';j++);
if (text[j])
Expand Down Expand Up @@ -545,8 +543,7 @@ int window_calc(Uint32 steps)
case 0:
if (elem->type == -1)
spMapSetByID( MAP_JUMP, 1 );
else
if (window->selection != nr)
if (elem->type != 0 || elem->type != 2 || window->selection != nr)
spGetInput()->touchscreen.pressed = 0;
window->selection = nr;
break;
Expand Down
2 changes: 1 addition & 1 deletion window.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int modal_window(pWindow window, void ( *resize )( Uint16 w, Uint16 h ));
pWindow create_text_box(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ), char* caption, char* text,int len,int show_selection,int* sprite_count,int insult_button);
void delete_window(pWindow window);

void draw_edgy_rectangle(int x, int y, int * width, int * height, int B0, int B1, int B2,int B4);
void draw_edgy_rectangle(int x, int y, int * width, int * height, int B1, int B2);

int message_box(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ), char* caption);
int text_box(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ), char* caption, char* text,int len,int show_selection,int* sprite_count,int insult_button);
Expand Down

0 comments on commit dd3569d

Please sign in to comment.