2017-04-29 18:43:17 +00:00
|
|
|
//main file
|
|
|
|
|
|
|
|
#include<iostream>
|
|
|
|
#include<SDL2/SDL.h>
|
|
|
|
#include"player.h"
|
|
|
|
#include"block.h"
|
2017-04-30 16:23:47 +00:00
|
|
|
#include"camera.h"
|
2017-04-29 18:43:17 +00:00
|
|
|
|
|
|
|
const int SCREEN_WIDTH = 640;
|
|
|
|
const int SCREEN_HEIGHT = 480;
|
|
|
|
|
|
|
|
SDL_Window* gWindow = NULL;
|
|
|
|
SDL_Renderer* gRenderer = NULL;
|
|
|
|
|
|
|
|
//12 sz of height and 16 of width
|
|
|
|
const int sz = SCREEN_WIDTH/16;
|
|
|
|
|
|
|
|
void init();
|
|
|
|
bool loadMedia();
|
|
|
|
void close();
|
|
|
|
|
|
|
|
bool loadMedia(){
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(){
|
|
|
|
SDL_Init(SDL_INIT_VIDEO);
|
2017-04-29 19:11:29 +00:00
|
|
|
gWindow = SDL_CreateWindow("Platform Test!",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,SCREEN_WIDTH,SCREEN_HEIGHT,SDL_WINDOW_SHOWN);
|
2017-04-29 18:43:17 +00:00
|
|
|
gRenderer = SDL_CreateRenderer(gWindow,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
|
|
|
SDL_SetRenderDrawColor(gRenderer,0xFF,0xFF,0xFF,0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void close(){
|
|
|
|
SDL_DestroyRenderer(gRenderer);
|
|
|
|
SDL_DestroyWindow(gWindow);
|
|
|
|
gWindow = NULL;
|
|
|
|
gRenderer = NULL;
|
|
|
|
|
|
|
|
SDL_Quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* args[]){
|
|
|
|
init();
|
|
|
|
loadMedia();
|
|
|
|
|
|
|
|
bool quit = false;
|
|
|
|
SDL_Event e;
|
2017-04-30 19:23:48 +00:00
|
|
|
|
|
|
|
Player posweg;
|
|
|
|
Camera camera(36*sz,SCREEN_WIDTH);
|
2017-04-29 18:43:17 +00:00
|
|
|
|
2017-04-30 16:23:47 +00:00
|
|
|
Block wallA(8*sz,SCREEN_HEIGHT-sz*5,sz*2,sz*2,&gRenderer);
|
|
|
|
Block wallB(4*sz,SCREEN_HEIGHT-sz*3,sz,sz*2,&gRenderer);
|
|
|
|
Block wallC(6*sz,SCREEN_HEIGHT-sz*3,sz,sz*2,&gRenderer);
|
|
|
|
Block ground(0,SCREEN_HEIGHT-sz,SCREEN_WIDTH,sz,&gRenderer);
|
2017-04-30 19:23:48 +00:00
|
|
|
Block ground2(SCREEN_WIDTH+sz*4,SCREEN_HEIGHT-sz,SCREEN_WIDTH,sz,&gRenderer);
|
2017-05-02 18:56:32 +00:00
|
|
|
Block powerup(13*sz,SCREEN_HEIGHT-sz*4,20,20,&gRenderer);
|
2017-04-30 16:23:47 +00:00
|
|
|
|
2017-04-29 18:43:17 +00:00
|
|
|
posweg.init(100,100,sz,sz,&gRenderer);
|
|
|
|
|
|
|
|
while(!quit){
|
|
|
|
while(SDL_PollEvent(&e)!=0){
|
|
|
|
if(e.type == SDL_QUIT){
|
|
|
|
quit = true;
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 17:40:03 +00:00
|
|
|
SDL_SetRenderDrawColor(gRenderer,0,0,100,0xFF);
|
2017-04-30 16:23:47 +00:00
|
|
|
SDL_RenderClear(gRenderer);
|
2017-05-01 17:40:03 +00:00
|
|
|
|
2017-04-30 16:23:47 +00:00
|
|
|
camera.update(posweg.getRectangle().x,posweg.getRectangle().y);
|
|
|
|
|
|
|
|
posweg.print(camera.getPosX());
|
2017-04-29 18:43:17 +00:00
|
|
|
|
2017-04-30 16:23:47 +00:00
|
|
|
wallA.print(camera.getPosX());
|
|
|
|
wallB.print(camera.getPosX());
|
|
|
|
wallC.print(camera.getPosX());
|
|
|
|
ground.print(camera.getPosX());
|
2017-04-30 19:23:48 +00:00
|
|
|
ground2.print(camera.getPosX());
|
2017-05-02 18:56:32 +00:00
|
|
|
powerup.print(camera.getPosX());
|
2017-04-30 16:23:47 +00:00
|
|
|
|
|
|
|
posweg.check(wallA.getRectangle());
|
|
|
|
posweg.check(wallB.getRectangle());
|
|
|
|
posweg.check(wallC.getRectangle());
|
|
|
|
posweg.check(ground.getRectangle());
|
2017-04-30 19:23:48 +00:00
|
|
|
posweg.check(ground2.getRectangle());
|
2017-05-02 18:56:32 +00:00
|
|
|
posweg.check(powerup.getRectangle());
|
2017-04-30 19:23:48 +00:00
|
|
|
|
2017-04-30 16:23:47 +00:00
|
|
|
SDL_RenderPresent(gRenderer);
|
2017-04-29 18:43:17 +00:00
|
|
|
}
|
|
|
|
close();
|
|
|
|
return 0;
|
|
|
|
}
|