From 6e60d17850b1efe55b6b008dc78c52dbc0b3b7e0 Mon Sep 17 00:00:00 2001 From: Nathan Misner Date: Sun, 26 Jun 2022 21:08:31 -0400 Subject: [PATCH] improved ball launching mechanics --- ball.cpp | 12 ++++++++++-- game.cpp | 4 ++++ game.h | 3 +++ main.cpp | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ball.cpp b/ball.cpp index 8e3adf3..292ebad 100644 --- a/ball.cpp +++ b/ball.cpp @@ -153,13 +153,20 @@ void Ball::move() { texture = ballTextures->getTexture(ballMode - POWER_BALL); if (state == BALL_STATE_INIT) { - x = shipLeft + ((shipRight - shipLeft) / 2) - (BALL_WIDTH / 2); + x = Game_ShipPos() + (SHIP_WIDTH / 2) - (BALL_WIDTH / 2); y = SHIP_YPOS; + // allow player to choose where the ball goes + if (shipSpeed < 0) { + setAngle(135); + } + else if (shipSpeed > 0) { + setAngle(45); + } + //don't allow ball launch until level is done loading and ship is done if ((padData & PAD_LASER) && (gameLevel->doneLoad()) && (shipState == SHIP_STATE_NORM)) { speed = BALL_MINSPEED; - setAngle(45); state = BALL_STATE_NORMAL; } } @@ -279,6 +286,7 @@ void Ball_Add(float x, float y, float angle) { //if spawning the first ball, attach it to the ship Ball ball = Ball(ballTextures->getTexture(ballMode - POWER_BALL), -80, -80, 0); ball.state = BALL_STATE_INIT; // ball attached to ship + ball.setAngle(45); balls.add(ball); } else { diff --git a/game.cpp b/game.cpp index 73907b8..0968ca6 100644 --- a/game.cpp +++ b/game.cpp @@ -355,6 +355,10 @@ void Game_IncLife() { lives++; } +float Game_ShipPos() { + return shipSprite.x; +} + void Game_Loss() { Hud_ChipSet(STATE_CHIP_BURNT); frames = 0; diff --git a/game.h b/game.h index b8d82d3..aa17336 100644 --- a/game.h +++ b/game.h @@ -95,6 +95,9 @@ void Game_IncPowerUp(); // gives the player a life void Game_IncLife(); +// returns the ship sprite's x position +float Game_ShipPos(); + // running this kills the player (in the game, not real life) void Game_Loss(); diff --git a/main.cpp b/main.cpp index 90c015d..fc71c8d 100644 --- a/main.cpp +++ b/main.cpp @@ -136,7 +136,7 @@ int main(int argc, char **argv) { SDL_Event event; int quit = 0; - int state = STATE_LOGO; + int state = STATE_STAGE; Stage_Init(); try { -- 2.45.2