Hey everyone!! First post here. I'm currently taking a C++ class for college and the second part of our text book deals with using AGK.
Please take a look at the following code:
// Includes, namespace and prototypes
#include "template.h"
using namespace AGK;
app App;
// Constants for the screen resolution
const int SCREEN_WIDTH = 640, SCREEN_HEIGHT = 480;
// Constants for the sprite indices
const int BALL1_SPRITE = 1;
const int BALL2_SPRITE = 2;
// Constant for ball 1's initial X position
const float BALL1_X = 0;
// Constant for ball 2's initial X position
const float BALL2_X = 511;
// Constant for the Y position of both sprites
const float BALL_Y = 175;
// Constant for the distance to move each frame
const float DISTANCE = 1;
// Begin app, called once at the start
void app::Begin( void )
{
// Set the virtual resolution and window title
agk::SetVirtualResolution(SCREEN_WIDTH, SCREEN_HEIGHT);
agk::SetWindowTitle("Randomly Moving Bowling Balls - Jacob Henley");
// Create the sprites
agk::CreateSprite(BALL1_SPRITE, "BowlingBall1.png");
agk::CreateSprite(BALL2_SPRITE, "BowlingBall2.png");
// Set the position of each sprite
agk::SetSpritePosition(BALL1_SPRITE, BALL1_X, BALL_Y);
agk::SetSpritePosition(BALL2_SPRITE, BALL2_X, BALL_Y);
}
// Main loop, called every frame
void app::Loop ( void )
{
// Get the X-coordinate of each sprite
float ball1x = agk::GetSpriteX(BALL1_SPRITE);
float ball2x = agk::GetSpriteX(BALL2_SPRITE);
// Determine if the two sprites have collided
if (agk::GetSpriteCollision(BALL1_SPRITE, BALL2_SPRITE))
{
// Reset the sprites to random locations
agk::SetSpriteX(BALL1_SPRITE, BALL1_X);
agk::SetSpriteX(BALL2_SPRITE, BALL2_X);
}
else
{
// Move ball 1 to the right
agk::SetSpriteX(BALL1_SPRITE, ball1x + DISTANCE);
// Move ball 2 to the left
agk::SetSpriteX(BALL2_SPRITE, ball2x - DISTANCE);
}
// Refresh the screen
agk::Sync();
}
// Called when the app ends
void app::End ( void )
{
}
I need to modify this program so that the bowling balls move in random directions. If a ball reaches the edge of the screen, it should change directions. If the balls collide, they should be repositioned back at their random locations.
Any help with this would be greatly appreciated. Thanks!!!