fix: better speed + random initial direction
This commit is contained in:
15
main.cpp
15
main.cpp
@@ -3,7 +3,10 @@
|
||||
#include <SDL3/SDL_events.h>
|
||||
#include <SDL3/SDL_keyboard.h>
|
||||
#include <SDL3/SDL_thread.h>
|
||||
#include <cstdlib>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctime>
|
||||
#include <math.h>
|
||||
#include <GLES3/gl3.h>
|
||||
|
||||
@@ -40,7 +43,7 @@ static float ballVelY = 0.5f;
|
||||
static float ballSpeed = 600.f;
|
||||
static float ballAccel = 25.f;
|
||||
|
||||
static float opponentSpeed = 450.f;
|
||||
static float opponentSpeed = 1200.f;
|
||||
static float opponentVelY = 0.f;
|
||||
|
||||
const char* vShader = "#version 300 es\n"
|
||||
@@ -175,6 +178,8 @@ static Rect opponent(
|
||||
bool paused = true;
|
||||
|
||||
extern "C" int APP_MAIN(int argc, char **argv) {
|
||||
srand(time(NULL));
|
||||
|
||||
SDL_SetAppMetadata("Example Renderer Primitives", "1.0", "com.example.renderer-primitives");
|
||||
SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight");
|
||||
|
||||
@@ -269,8 +274,16 @@ extern "C" int APP_MAIN(int argc, char **argv) {
|
||||
}
|
||||
if (paused && event.type == SDL_EVENT_KEY_DOWN && event.key.key == SDLK_SPACE) {
|
||||
paused = false;
|
||||
ball.x = SCREEN_WIDTH / 2 - BALL_SIZE / 2;
|
||||
ball.y = SCREEN_HEIGHT / 2 - BALL_SIZE / 2;
|
||||
ballVelX = ((float)rand() / (float)RAND_MAX) * 2.f - 1.f;
|
||||
ballVelY = ((float)rand() / (float)RAND_MAX) * 2.f - 1.f;
|
||||
} else if (paused && event.type == SDL_EVENT_FINGER_UP) {
|
||||
paused = false;
|
||||
ball.x = SCREEN_WIDTH / 2 - BALL_SIZE / 2;
|
||||
ball.y = SCREEN_HEIGHT / 2 - BALL_SIZE / 2;
|
||||
ballVelX = (float)rand() / (float)RAND_MAX * 2 - 1;
|
||||
ballVelY = (float)rand() / (float)RAND_MAX * 2 - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user