From 07fa7468e42c0c782caf12c6c8cb3c125672a0f4 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 8 Jul 2017 17:07:33 +1000 Subject: [PATCH] Rough fix for pong's input issues --- qcsrc/common/minigames/minigame/pong.qc | 63 ++++++++++++++++--------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/qcsrc/common/minigames/minigame/pong.qc b/qcsrc/common/minigames/minigame/pong.qc index 55d41617d..dd072a05b 100644 --- a/qcsrc/common/minigames/minigame/pong.qc +++ b/qcsrc/common/minigames/minigame/pong.qc @@ -123,9 +123,14 @@ bool pong_paddle_hit(entity ball, int pteam) entity paddle = ball.owner.pong_paddles[pteam-1]; if (!paddle) return false; - vector near_point = box_nearest(paddle.mins+paddle.origin, - paddle.maxs+paddle.origin, ball.origin); + +#if 1 + vector near_point = box_nearest(paddle.m_mins+paddle.origin, + paddle.m_maxs+paddle.origin, ball.origin); return vdist(near_point - ball.origin, <=, ball.pong_length); +#else + return boxesoverlap(paddle.m_mins + paddle.origin, paddle.m_maxs + paddle.origin, ball.m_mins + ball.origin, ball.m_maxs + ball.origin); +#endif } // Checks for a goal, when that happes adds scores and resets the ball @@ -275,16 +280,16 @@ void pong_paddle_think(entity this) if ( this.realowner.minigame_players.pong_keys == PONG_KEY_INCREASE || this.realowner.minigame_players.pong_keys == PONG_KEY_DECREASE ) { - float movement = autocvar_sv_minigames_pong_paddle_speed * think_speed; + float pmovement = autocvar_sv_minigames_pong_paddle_speed * think_speed; float halflen = this.pong_length/2; if ( this.realowner.minigame_players.pong_keys == PONG_KEY_DECREASE ) - movement *= -1; + pmovement *= -1; if ( this.team > 2 ) - this.origin_x = bound(halflen, this.origin_x+movement, 1-halflen); + this.origin_x = bound(halflen, this.origin_x+pmovement, 1-halflen); else - this.origin_y = bound(halflen, this.origin_y+movement, 1-halflen); + this.origin_y = bound(halflen, this.origin_y+pmovement, 1-halflen); this.SendFlags |= MINIG_SF_UPDATE; } @@ -319,8 +324,8 @@ entity pong_paddle_spawn(entity minigame, int pl_team, entity real_player) setthink(paddle, pong_paddle_think); paddle.nextthink = time; paddle.team = pl_team; - paddle.mins = pong_team_to_box_halfsize(pl_team,-paddle.pong_length,-1/16); - paddle.maxs = pong_team_to_box_halfsize(pl_team,paddle.pong_length,1/16); + paddle.m_mins = pong_team_to_box_halfsize(pl_team,-paddle.pong_length,-1/16); + paddle.m_maxs = pong_team_to_box_halfsize(pl_team,paddle.pong_length,1/16); if ( real_player == NULL ) pong_ai_spawn(paddle); @@ -393,12 +398,13 @@ int pong_server_event(entity minigame, string event, ...) (minigame.minigame_flags & ~PONG_STATUS_WAIT); minigame.SendFlags |= MINIG_SF_UPDATE; - int i; entity ball; - for ( i = 0; i < autocvar_sv_minigames_pong_ball_number; i++ ) + for ( int j = 0; j < autocvar_sv_minigames_pong_ball_number; j++ ) { ball = msle_spawn(minigame,"pong_ball"); ball.pong_length = autocvar_sv_minigames_pong_ball_radius; + ball.m_mins = vec2(-ball.pong_length, -ball.pong_length); + ball.m_maxs = vec2(ball.pong_length, ball.pong_length); pong_ball_reset(ball); } } @@ -415,15 +421,18 @@ int pong_server_event(entity minigame, string event, ...) case "-moved": player.pong_keys &= ~PONG_KEY_DECREASE; return true; + case "move": + if(argv(1)) + player.pong_keys = stoi(argv(1)); + return true; case "pong_aimore": { - int i; if ( minigame.minigame_flags & PONG_STATUS_WAIT ) - for ( i = 0; i < PONG_MAX_PLAYERS; i++ ) + for ( int j = 0; j < PONG_MAX_PLAYERS; j++ ) { - if ( minigame.pong_paddles[i] == NULL ) + if ( minigame.pong_paddles[j] == NULL ) { - pong_paddle_spawn(minigame,i+1,NULL); + pong_paddle_spawn(minigame,j+1,NULL); return true; } } @@ -435,14 +444,13 @@ int pong_server_event(entity minigame, string event, ...) if ( minigame.minigame_flags & PONG_STATUS_WAIT ) { entity paddle; - int i; - for ( i = PONG_MAX_PLAYERS-1; i >= 0; i-- ) + for ( int j = PONG_MAX_PLAYERS-1; j >= 0; j-- ) { - paddle = minigame.pong_paddles[i]; + paddle = minigame.pong_paddles[j]; if ( paddle != NULL && paddle.realowner.classname == "pong_ai" ) { - minigame.pong_paddles[i] = NULL; + minigame.pong_paddles[j] = NULL; delete(paddle.realowner); delete(paddle); return true; @@ -499,9 +507,16 @@ vector pong_team_to_color(int nteam) } } +int pong_keys_pressed; +int pong_keys_pressed_old; + // Required function, draw the game board void pong_hud_board(vector pos, vector mySize) { + if(pong_keys_pressed != pong_keys_pressed_old) + minigame_cmd(strcat("move ", itos(pong_keys_pressed))); + pong_keys_pressed_old = pong_keys_pressed; + minigame_hud_fitsqare(pos, mySize); minigame_hud_simpleboard(pos,mySize,minigame_texture("pong/board")); @@ -602,13 +617,15 @@ int pong_client_event(entity minigame, string event, ...) case K_KP_UPARROW: case K_LEFTARROW: case K_KP_LEFTARROW: - minigame_cmd("+moved"); + //minigame_cmd("+moved"); + pong_keys_pressed |= PONG_KEY_DECREASE; return true; case K_DOWNARROW: case K_KP_DOWNARROW: case K_RIGHTARROW: case K_KP_RIGHTARROW: - minigame_cmd("+movei"); + //minigame_cmd("+movei"); + pong_keys_pressed |= PONG_KEY_INCREASE; return true; } return false; @@ -619,13 +636,15 @@ int pong_client_event(entity minigame, string event, ...) case K_KP_UPARROW: case K_LEFTARROW: case K_KP_LEFTARROW: - minigame_cmd("-moved"); + //minigame_cmd("-moved"); + pong_keys_pressed &= ~PONG_KEY_DECREASE; return true; case K_DOWNARROW: case K_KP_DOWNARROW: case K_RIGHTARROW: case K_KP_RIGHTARROW: - minigame_cmd("-movei"); + //minigame_cmd("-movei"); + pong_keys_pressed &= ~PONG_KEY_INCREASE; return true; } return false; -- 2.39.2