Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SDL.h"
- #include "SDL_image.h"
- #include <string>
- #include "constants.h"
- #include "classes.h"
- #include "functions.h"
- #include "globals.h"
- Block::Block()
- {
- y = -1;
- x = -1;
- ShowBlock = 0;
- ShapeColor = 1;
- }
- int Block::Getx()
- {
- return x;
- }
- int Block::Gety()
- {
- return y;
- }
- void Block::Setx(int xvalue)
- {
- x = xvalue;
- }
- void Block::Sety(int yvalue)
- {
- y = yvalue;
- }
- void Block::DisplayBlocks()
- {
- if (ShowBlock == 1)
- {
- if (ShapeColor == 1)
- apply_surface(x, y, skyrider, screen);
- if (ShapeColor == 2)
- apply_surface(x, y, JShapeBlock, screen);
- if (ShapeColor == 3)
- apply_surface(x, y, LShapeBlock, screen);
- if (ShapeColor == 4)
- apply_surface(x, y, OShapeBlock, screen);
- if (ShapeColor == 5)
- apply_surface(x, y, ZShapeBlock, screen);
- if (ShapeColor == 6)
- apply_surface(x, y, TShapeBlock, screen);
- if (ShapeColor == 7)
- apply_surface(x, y, SShapeBlock, screen);
- }
- }
- void Block::SetShowBlock(bool OnOff)
- {
- ShowBlock = OnOff;
- }
- bool Block::GetShowBlock()
- {
- return ShowBlock;
- }
- void Block::SetShapeColor(int shapecolorvalue)
- {
- ShapeColor = shapecolorvalue;
- }
- Shape::Shape()
- {
- shape = 0;
- RxVel = 0;
- LxVel = 0;
- yVel = 0;
- yVelFast = 0;
- LxVelFast = 0;
- RxVelFast = 0;
- FlipShape = 0;
- orientation = 1;
- Fast = 0;
- pause = false;
- restart = false;
- }
- void Shape::SetRestart(bool restartvalue)
- {
- restart = restartvalue;
- }
- void Shape::Rotate(Block* aBlock, Shape aShape, int maxsize)
- {
- int counter = 0;
- int CurrentxPosition[4] = {0};
- int CurrentyPosition[4] = {0};
- while (counter < 4)
- {
- CurrentxPosition[counter] = aBlock[aShape.GetBlockMarker(counter)].Getx();
- CurrentyPosition[counter] = aBlock[aShape.GetBlockMarker(counter)].Gety();
- counter++;
- }
- while (FlipShape == true)
- {
- //I shape
- if (shape == 1)
- {
- if (orientation == 1 || orientation == 3)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + (BLOCK_WIDTH * 2));
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- }
- if (orientation == 2 || orientation == 4)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + (BLOCK_HEIGHT * 2));
- }
- }
- //JShape
- if (shape == 2)
- {
- if (orientation == 1)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- }
- if (orientation == 2)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- if (orientation == 3)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- }
- if (orientation == 4)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- }
- }
- //LShape
- if (shape == 3)
- {
- if (orientation == 1)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- }
- if (orientation == 2)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- if (orientation == 3)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- }
- if (orientation == 4)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- }
- }
- //skip 4 because 4 is the square with the same position every time
- //ZShape
- if (shape == 5)
- {
- if (orientation == 1)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- if (orientation == 2)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- if (orientation == 3)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- if (orientation == 4)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- }
- //TShape
- if (shape == 6)
- {
- if (orientation == 1)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
- aBlock[aShape.GetBlockMarker(1)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(1)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() + BLOCK_HEIGHT);
- }
- if (orientation == 2)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(1)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
- aBlock[aShape.GetBlockMarker(1)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety()+ BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
- }
- if (orientation == 3)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
- aBlock[aShape.GetBlockMarker(1)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(1)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
- }
- if (orientation == 4)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(1)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
- aBlock[aShape.GetBlockMarker(1)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
- }
- }
- //SShape
- if (shape == 7)
- {
- if (orientation == 1)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- if (orientation == 2)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- if (orientation == 3)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- if (orientation == 4)
- {
- aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
- aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
- aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
- aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
- }
- }
- orientation++;
- if (orientation == 5)
- orientation = 1;
- FlipShape = false;
- }
- int CollisionResult = -1;
- CollisionResult = aShape.CheckCollision(aBlock, maxsize, CurrentyPosition, CurrentxPosition);
- if (CollisionResult == 1)
- {
- counter = 0;
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
- aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
- counter++;
- }
- }
- if (CollisionResult == 2)
- {
- counter = 0;
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
- aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
- counter++;
- }
- }
- }
- bool Shape::move(Block* aBlock, Shape aShape, int maxsize)
- {
- int counter = 0;
- int CurrentxPosition[4] = {0};
- int CurrentyPosition[4] = {0};
- while (counter < 4)
- {
- CurrentxPosition[counter] = aBlock[aShape.GetBlockMarker(counter)].Getx();
- CurrentyPosition[counter] = aBlock[aShape.GetBlockMarker(counter)].Gety();
- counter++;
- }
- counter = 0;
- while (RxVel == true)
- {
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter] + BLOCK_WIDTH);
- counter++;
- }
- RxVel = false;
- }
- counter = 0;
- while (LxVel == true)
- {
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter] - BLOCK_WIDTH);
- counter++;
- }
- LxVel = false;
- }
- counter = 0;
- while (yVel == true)
- {
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter] + BLOCK_HEIGHT);
- counter++;
- }
- yVel = false;
- }
- //This section is to make it so if you're holding down a direction, it'll go fast in that direction.
- //I wasn't sure how to do this to be honest, and this is the first thing I came up with that worked.
- //I'm 100% sure I'm doing this in a silly way, but I'm not sure how it should be done.
- counter = 0;
- if (Fast == true)
- {
- if (LxVelFast == true)
- {
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter] - BLOCK_WIDTH);
- counter++;
- }
- }
- counter = 0;
- if (yVelFast == true)
- {
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter] + BLOCK_HEIGHT);
- counter++;
- }
- }
- counter = 0;
- if (RxVelFast == true)
- {
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter] + BLOCK_WIDTH);
- counter++;
- }
- }
- }
- int CollisionResult = -1;
- CollisionResult = aShape.CheckCollision(aBlock, maxsize, CurrentyPosition, CurrentxPosition);
- if (CollisionResult == 1)
- {
- counter = 0;
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
- aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
- counter++;
- }
- return 0;
- }
- if (CollisionResult == 2)
- {
- counter = 0;
- while (counter < 4)
- {
- aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
- aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
- counter++;
- }
- return 1;
- }
- return 0;
- }
- int Shape::CheckCollision(Block* aBlock, int maxsize, int* OriginalyPosition, int* OriginalxPosition)
- {
- int counter = 0;
- int NewxPosition[4] = {0};
- int NewyPosition[4] = {0};
- while (counter < 4)
- {
- NewxPosition[counter] = aBlock[GetBlockMarker(counter)].Getx();
- NewyPosition[counter] = aBlock[GetBlockMarker(counter)].Gety();
- counter++;
- }
- counter = 0;
- //Too far to right
- while (counter < 4)
- {
- if (NewxPosition[counter] + BLOCK_WIDTH > SCREEN_PLAYABLE_WIDTH)
- return 1;
- counter++;
- }
- counter = 0;
- while (counter < 4)
- {
- if (NewxPosition[counter] < 0)
- return 1;
- counter++;
- }
- counter = 0;
- //Too far down
- while (counter < 4)
- {
- if (NewyPosition[counter] + BLOCK_HEIGHT > SCREEN_HEIGHT)
- return 2;
- counter++;
- }
- counter = 0;
- int counter2 = 0;
- //Collision with another block
- while (counter < (maxsize - 1))
- {
- while (counter2 < 4){
- if (aBlock[counter].Getx() != -1 && counter != GetBlockMarker(0) && counter != GetBlockMarker(1) && counter != GetBlockMarker(2) && counter != GetBlockMarker(3))
- if (NewyPosition[counter2] == aBlock[counter].Gety())
- if (NewxPosition[counter2] == aBlock[counter].Getx())
- {
- counter = 0;
- counter2 = 0;
- while (counter < (maxsize - 1))
- {
- while (counter2 < 4)
- {
- if (aBlock[counter].Getx() != -1 && counter != GetBlockMarker(0) && counter != GetBlockMarker(1) && counter != GetBlockMarker(2) && counter != GetBlockMarker(3))
- if (OriginalyPosition[counter2] + BLOCK_HEIGHT == NewyPosition[counter2])
- if (OriginalyPosition[counter2] + BLOCK_HEIGHT == aBlock[counter].Gety())
- if (OriginalxPosition[counter2] == aBlock[counter].Getx())
- {
- return 2;
- }
- counter2++;
- }
- counter++;
- counter2 = 0;
- }
- return 1;
- }
- counter2++;
- }
- counter2 = 0;
- counter++;
- }
- return 0;
- }
- void Shape::SetFast(bool fastvalue)
- {
- Fast = fastvalue;
- if (fastvalue == 0)
- {
- LxVelFast = RxVelFast = yVelFast = 0;
- }
- }
- bool Shape::GetIfKeyHeldDown()
- {
- if (LxVelFast == true || RxVelFast == true || yVelFast == true)
- return 1;
- return 0;
- }
- void Shape::SetOrientation(int OrientationValue)
- {
- orientation = OrientationValue;
- }
- void Shape::SetShape(int shapevalue, Block* aBlock, int maxsize)
- {
- shape = shapevalue;
- int counter = 0, index = 0, xvalue = 0, yvalue = 0, BlockMarkerIndex = 0,
- SetOrientation(1);
- //I shape
- if (shape == 1)
- {
- xvalue = 175;
- yvalue = 0;
- while (counter < 4)
- {
- if (index >= maxsize)
- index = 0;
- while (aBlock[index].Getx() != -1)
- {
- index++;
- if (index >= maxsize)
- index = 0;
- }
- if (counter == 1)
- yvalue = BLOCK_HEIGHT;
- else if (counter !=1 && counter != 0)
- yvalue += BLOCK_HEIGHT;
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(1);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //J Shape
- if (shape == 2)
- {
- xvalue = SCREEN_PLAYABLE_WIDTH / 2;
- yvalue = 0;
- while (counter < 4)
- {
- if (index >= maxsize)
- index = 0;
- while (aBlock[index].Getx() != -1)
- {
- index++;
- if (index >= maxsize)
- index = 0;
- }
- if (counter == 1)
- yvalue = BLOCK_HEIGHT;
- else if (counter != 1 && counter != 0)
- yvalue += yvalue;
- if (counter == 3)
- {
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
- yvalue = BLOCK_HEIGHT * 2;
- }
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(2);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //L Shape
- if (shape == 3)
- {
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
- yvalue = 0;
- while (counter < 4)
- {
- if (index >= maxsize)
- index = 0;
- while (aBlock[index].Getx() != -1)
- {
- index++;
- if (index >= maxsize)
- index = 0;
- }
- if (counter == 1 || counter == 2)
- {
- yvalue = 35;
- yvalue = yvalue * counter;
- }
- if (counter == 3)
- {
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
- yvalue = BLOCK_HEIGHT * 2;
- }
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(3);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //O Shape
- if (shape == 4)
- {
- yvalue = 0;
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
- while (counter < 4)
- {
- if (index >= maxsize)
- index = 0;
- while (aBlock[index].Getx() != -1)
- {
- index++;
- if (index >= maxsize)
- index = 0;
- }
- if (counter == 1)
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
- if (counter == 2)
- {
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
- yvalue = BLOCK_HEIGHT;
- }
- if (counter == 3)
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(4);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //Z Shape
- if (shape == 5)
- {
- yvalue = 0;
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
- while (counter < 4)
- {
- if (index >= maxsize)
- index = 0;
- while (aBlock[index].Getx() != -1)
- {
- index++;
- if (index >= maxsize)
- index = 0;
- }
- if (counter == 1)
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
- else if (counter == 2)
- yvalue = BLOCK_HEIGHT;
- else if (counter == 3)
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2) + BLOCK_WIDTH;
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(5);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //T Shape
- if (shape == 6)
- {
- yvalue = BLOCK_HEIGHT;
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - (BLOCK_WIDTH);
- while (counter < 4)
- {
- if (index >= maxsize)
- index = 0;
- while (aBlock[index].Getx() != -1)
- {
- index++;
- if (index >= maxsize)
- index = 0;
- }
- if (counter == 1)
- {
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
- yvalue = 0;
- }
- if (counter == 2)
- yvalue = BLOCK_HEIGHT;
- if (counter == 3)
- {
- xvalue += BLOCK_WIDTH;
- }
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(6);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //S Shape
- if (shape == 7)
- {
- yvalue = BLOCK_HEIGHT;
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
- while (counter < 4)
- {
- if (index >= maxsize)
- index = 0;
- while (aBlock[index].Getx() != -1)
- {
- index++;
- if (index >= maxsize)
- index = 0;
- }
- if (counter == 1)
- xvalue += BLOCK_WIDTH;
- if (counter == 2)
- yvalue = 0;
- if (counter == 3)
- xvalue = (SCREEN_PLAYABLE_WIDTH / 2) + BLOCK_WIDTH;
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(7);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- }
- void Shape::SetBlockMarker(int value, int index)
- {
- BlockMarker[index] = value;
- }
- int Shape::GetBlockMarker(int index)
- {
- return BlockMarker[index];
- }
- bool Shape::GetRestart()
- {
- return restart;
- }
- void Shape::handle_input()
- {
- if(event.type == SDL_KEYDOWN)
- {
- switch(event.key.keysym.sym)
- {
- case SDLK_UP: FlipShape = true; break;
- case SDLK_DOWN: yVel = true; yVelFast = true; break;
- case SDLK_LEFT: LxVel = true; LxVelFast = true; break;
- case SDLK_RIGHT: RxVel = true; RxVelFast = true; break;
- case SDLK_BACKSPACE:
- if (pause == true)
- pause = false;
- else
- pause = true;
- break;
- case SDLK_RETURN: restart = true; break;
- }
- }
- //If a key was released
- else if(event.type == SDL_KEYUP)
- {
- //Adjust the velocity
- switch(event.key.keysym.sym)
- {
- case SDLK_UP: break;
- case SDLK_DOWN: yVelFast = false; break;
- case SDLK_LEFT: LxVelFast = false; break;
- case SDLK_RIGHT: RxVelFast = false; break;
- case SDLK_BACKSPACE: break;
- }
- }
- }
- bool Shape::MoveShapeDown(Block* aBlock, Shape aShape, int maxsize)
- {
- int counter = 0;
- int CurrentxPosition[4] = {0};
- int CurrentyPosition[4] = {0};
- while (counter < 4)
- {
- CurrentxPosition[counter] = aBlock[GetBlockMarker(counter)].Getx();
- CurrentyPosition[counter] = aBlock[GetBlockMarker(counter)].Gety();
- counter++;
- }
- counter = 0;
- while (counter < 4)
- {
- aBlock[GetBlockMarker(counter)].Sety(CurrentyPosition[counter] + BLOCK_HEIGHT);
- counter++;
- }
- //Check Collision
- int CollisionResult = -1;
- CollisionResult = CheckCollision(aBlock, maxsize, CurrentyPosition, CurrentxPosition);
- if (CollisionResult == 1)
- {
- counter = 0;
- while (counter < 4)
- {
- aBlock[GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
- aBlock[GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
- counter++;
- }
- return 0;
- }
- if (CollisionResult == 2)
- {
- counter = 0;
- while (counter < 4)
- {
- aBlock[GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
- aBlock[GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
- counter++;
- }
- return 1;
- }
- return 0;
- }
- void Shape::SpawnNewShapeIfNeeded(bool &SpawnShapeAnswer, Block* aBlock, int maxsize, int &nextblockshape, int &linesclearedint, int &scorevalue)
- {
- if (SpawnShapeAnswer == true)
- {
- SetShape(nextblockshape, aBlock, maxsize);
- nextblockshape = 1 + (rand() % 6);
- CheckForLine(aBlock, maxsize, linesclearedint, scorevalue);
- SetFast(0);
- }
- SpawnShapeAnswer = 0;
- }
- void Shape::SpawnNextShapeInSidebar(int shapevalue, Block* aBlock)
- {
- shape = shapevalue;
- int counter = 0, index = 0, xvalue = 0, yvalue = 0, BlockMarkerIndex = 0;
- //I shape
- if (shape == 1)
- {
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
- yvalue = 0;
- while (counter < 4)
- {
- if (counter == 1)
- yvalue = BLOCK_HEIGHT;
- else if (counter !=1 && counter != 0)
- yvalue += BLOCK_HEIGHT;
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(1);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //J Shape
- if (shape == 2)
- {
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
- yvalue = 0;
- while (counter < 4)
- {
- if (counter == 1)
- yvalue = BLOCK_HEIGHT;
- else if (counter != 1 && counter != 0)
- yvalue += yvalue;
- if (counter == 3)
- {
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) - BLOCK_WIDTH;
- yvalue = BLOCK_HEIGHT * 2;
- }
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(2);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //L Shape
- if (shape == 3)
- {
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
- yvalue = 0;
- while (counter < 4)
- {
- if (counter == 1 || counter == 2)
- {
- yvalue = 35;
- yvalue = yvalue * counter;
- }
- if (counter == 3)
- {
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) + BLOCK_WIDTH;
- yvalue = BLOCK_HEIGHT * 2;
- }
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(3);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //O Shape
- if (shape == 4)
- {
- yvalue = 0;
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - BLOCK_WIDTH;
- while (counter < 4)
- {
- if (counter == 1)
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH;
- if (counter == 2)
- {
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - BLOCK_WIDTH;
- yvalue = BLOCK_HEIGHT;
- }
- if (counter == 3)
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH;
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(4);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //Z Shape
- if (shape == 5)
- {
- yvalue = 0;
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) - BLOCK_WIDTH;
- while (counter < 4)
- {
- if (counter == 1)
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
- else if (counter == 2)
- yvalue = BLOCK_HEIGHT;
- else if (counter == 3)
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) + BLOCK_WIDTH;
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(5);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //T Shape
- if (shape == 6)
- {
- yvalue = BLOCK_HEIGHT;
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) - (BLOCK_WIDTH);
- while (counter < 4)
- {
- if (counter == 1)
- {
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
- yvalue = 0;
- }
- if (counter == 2)
- yvalue = BLOCK_HEIGHT;
- if (counter == 3)
- {
- xvalue += BLOCK_WIDTH;
- }
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(6);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- //S Shape
- if (shape == 7)
- {
- yvalue = BLOCK_HEIGHT;
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) - BLOCK_WIDTH;
- while (counter < 4)
- {
- if (counter == 1)
- xvalue += BLOCK_WIDTH;
- if (counter == 2)
- yvalue = 0;
- if (counter == 3)
- xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) + BLOCK_WIDTH;
- aBlock[index].Setx(xvalue);
- aBlock[index].Sety(yvalue);
- aBlock[index].SetShowBlock(1);
- aBlock[index].SetShapeColor(7);
- BlockMarker[BlockMarkerIndex] = index;
- BlockMarkerIndex++;
- index++;
- counter++;
- }
- }
- }
- bool Shape::GetPause()
- {
- return pause;
- }
- void Shape::SetPause(bool pausevalue)
- {
- pause = pausevalue;
- }
- bool Shape::CheckGameOver(Block* aBlock, int maxsize)
- {
- int counter = 0;
- int counter2 = 0;
- int CurrentxPosition[4] = {0};
- int CurrentyPosition[4] = {0};
- while (counter < 4)
- {
- CurrentxPosition[counter] = aBlock[GetBlockMarker(counter)].Getx();
- CurrentyPosition[counter] = aBlock[GetBlockMarker(counter)].Gety();
- counter++;
- }
- counter = 0;
- while (counter < (maxsize - 1))
- {
- while (counter2 < 4){
- if (aBlock[counter].Getx() != -1 && counter != GetBlockMarker(0) && counter != GetBlockMarker(1) && counter != GetBlockMarker(2) && counter != GetBlockMarker(3))
- if (aBlock[counter].Gety() == 0)
- return 1;
- counter2++;
- }
- counter2 = 0;
- counter++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement