Skip to content
Snippets Groups Projects
Commit 5cd8f3ee authored by sgupta72's avatar sgupta72
Browse files

Done..

parent fbdb5f07
No related branches found
No related tags found
No related merge requests found
File added
File added
File added
File added
,shivam,shivam-Vostro-2520,13.11.2017 12:44,file:///home/shivam/.config/libreoffice/4;
\ No newline at end of file
all :
g++ main.cpp game.cpp window.cpp rect.cpp -lSDL2 -lSDL2_image
test :
g++ test.cpp game.cpp window.cpp rect.cpp -lSDL2 -lSDL2_image -o test
File added
File added
No preview for this file type
......@@ -33,7 +33,6 @@ void Game::GameLoop()
{
rects.push_back(new Rect("spritesheet.png", window, 4, 9));
rects[rects.size()-1]->Move(300, (9 * i + j) * 64);
cout << "here " << i << " " << j << " " << rects.size() << endl;
}
}
while(!quit)
......@@ -85,7 +84,6 @@ void Game::GameLoop()
{
for(int j = 0; j < 9; j++)
{
cout << "HERE" << i << " " << j << " " << rects.size() << " " << 9 * i + j << endl;
rects[9 * i + j]->Draw(window, i, j);
}
}
......
......@@ -87,7 +87,6 @@ void Rect::Draw(Window &window, int row, int column)
srcrect.y = (double(column)/double(columns)) * (image->w / columns);
srcrect.w = image->w/columns;
srcrect.h = image->h/rows;
cout << srcrect.x << " " << srcrect.y << " " << srcrect.w << " " << srcrect.h << endl;
SDL_Rect dstrect;
dstrect.x = x;
dstrect.y = y;
......@@ -115,7 +114,15 @@ void Rect::CorrectPosition(vector<Rect*> rects)
}
}
}
int Rect::get_x()
{
return x;
}
int Rect::get_y()
{
return y;
}
SDL_Surface *Rect::get_image()
{
return image;
......
......@@ -67,6 +67,10 @@ public:
* get image surface
**/
SDL_Surface *get_image();
int get_x();
int get_y();
private:
/**
* actually load image
......
test 0 → 100755
File added
test.cpp 0 → 100644
#include <cassert>
#include "rect.h"
using namespace std;
void TestRect()
{
Window window;
Rect rect("mario.png", window);
Rect rect2("mario.png", window);
rect.move(5, 5);
assert(rect.get_x() == 5);
assert(rect.get_y() == 5);
rect2.move(400, 400);
assert(rect2.get_x() == 400);
assert(rect2.get_y() == 400);
assert(!rect.CheckCollision(rect2));
rect2.move(6, 6);
assert(rect2.get_x() == 6);
assert(rect2.get_y() == 6);
assert(rect.CheckCollision(rect2));
rect.AddVelocity(1, 1);
for(int i = 0; i < 10; i++)
{
rect.UpdatePosition();
assert(rect.get_x() == (5 + (i+1)));
assert(rect.get_y() == (5 + i + 1));
}
}
int main()
{
TestRect();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment