1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
void Cube::handleEvent()
{
if(event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_RIGHT: xVel += 34;break;
case SDLK_LEFT: xVel -= 34; break;
case SDLK_DOWN: yVel += 34; break;
}
}
cube.x += xVel;
b1.move(xVel,0);
b2.move(xVel,0);
b3.move(xVel,0);
b4.move(xVel,0);
//dont go outside the grid
if(cube.x < 100 || cube.x > 440-cube.w)
{
cube.x -= xVel;
b1.move(-xVel,0);
b2.move(-xVel,0);
b3.move(-xVel,0);
b4.move(-xVel,0);
}
//fall autonomously
if(down.get_ticks() >= 1000)
{
yVel += 34;
down.start();
}
cube.y += yVel;
b1.move(0,yVel);
b2.move(0,yVel);
b3.move(0,yVel);
b4.move(0,yVel);
if(cube.y+ 68 > 710)
{
cube.y -= yVel;
b1.move(0,-yVel);
b2.move(0,-yVel);
b3.move(0,-yVel);
b4.move(0,-yVel);
}
// stop movement when not intended
xVel = 0;
yVel = 0;
}
|