#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
//Screen attributes
const int SCREEN_WIDTH = 1024;
const int SCREEN_HEIGHT = 720;
const int SCREEN_BPP = 32;
//The frame rate
const int FRAMES_PER_SECOND = 10;
//The dot dimensions
const int ACTOR_WIDTH = 108;
const int ACTOR_HEIGHT = 116;
//子弹尺寸
const int BULLET_WIDTH = 64;
const int BULLET_HEIGHT = 64;
const int ENEMY_WIDTH = 128;
const int ENEMY_HEIGHT = 128;
const int ACTOR_RIGHT = 0;
const int ACTOR_LEFT = 1;
const int ACTOR_UP = 2;
const int ACTOR_DOWN = 3;
const int BULLET_RIGHT = 0;
const int BULLET_LEFT = 1;
const int BULLET_UP = 2;
const int BULLET_DOWN = 3;
//The dimensions of the level
const int LEVEL_WIDTH = 2380;
const int LEVEL_HEIGHT = 2320;
//The surfaces
SDL_Surface *actor = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *bullet = NULL;
SDL_Surface *enemy = NULL;
//The event structure
SDL_Event event;
SDL_Rect clipsRight[ 4 ];
SDL_Rect clipsLeft[ 4 ];
SDL_Rect clipsUp[ 4 ];
SDL_Rect clipsDown[ 4 ];
SDL_Rect clipsBullet[ 4 ];
SDL_Rect clipsEnemy_Right[ 4 ];
SDL_Rect clipsEnemy_Left[ 4 ];
SDL_Rect clipsEnemy_Up[ 4 ];
SDL_Rect clipsEnemy_Down[ 4 ];
SDL_Rect wall[100];
//The camera
SDL_Rect camera = { 800, 800, SCREEN_WIDTH, SCREEN_HEIGHT };
class Actor
{
private:
SDL_Rect box; //设置盒子
int xVel, yVel; //速度
int frame; //帧数
int status; //状态
public:
Actor();
void handle_input();
void move();
void show();
void set_camera();
};
class Bullet
{
private:
SDL_Rect bullet_box; //子弹的盒子
int bullet_xVel, bullet_yVel; //子弹速度
int bullet_status; //子弹形态
public:
Bullet();
void bullet_handle_input();
void move();
void bullet_show();
};
class Enemy
{
private:
SDL_Rect enemy_box; //设置盒子
int enemy_xVel, enemy_yVel; //速度
int enemy_frame; //帧数
int enemy_status; //状态
public:
Enemy();
void move();
void enemy_show();
};
void set_clips()
{
//设置人物精灵图
clipsDown[ 0 ].x = 0;
clipsDown[ 0 ].y = 0;
clipsDown[ 0 ].w = ACTOR_WIDTH;
clipsDown[ 0 ].h = ACTOR_HEIGHT;
clipsDown[ 1 ].x = ACTOR_WIDTH;
clipsDown[ 1 ].y = 0;
clipsDown[ 1 ].w = ACTOR_WIDTH;
clipsDown[ 1 ].h = ACTOR_HEIGHT;
clipsDown[ 2 ].x = ACTOR_WIDTH * 2;
clipsDown[ 2 ].y = 0;
clipsDown[ 2 ].w = ACTOR_WIDTH;
clipsDown[ 2 ].h = ACTOR_HEIGHT;
clipsDown[ 3 ].x = ACTOR_WIDTH * 3;
clipsDown[ 3 ].y = 0;
clipsDown[ 3 ].w = ACTOR_WIDTH;
clipsDown[ 3 ].h = ACTOR_HEIGHT;
clipsLeft[ 0 ].x = 0;
clipsLeft[ 0 ].y = ACTOR_HEIGHT;
clipsLeft[ 0 ].w = ACTOR_WIDTH;
clipsLeft[ 0 ].h = ACTOR_HEIGHT;
clipsLeft[ 1 ].x = ACTOR_WIDTH;
clipsLeft[ 1 ].y = ACTOR_HEIGHT;
clipsLeft[ 1 ].w = ACTOR_WIDTH;
clipsLeft[ 1 ].h = ACTOR_HEIGHT;
clipsLeft[ 2 ].x = ACTOR_WIDTH * 2;
clipsLeft[ 2 ].y = ACTOR_HEIGHT;
clipsLeft[ 2 ].w = ACTOR_WIDTH;
clipsLeft[ 2 ].h = ACTOR_HEIGHT;
clipsLeft[ 3 ].x = ACTOR_WIDTH * 3;
clipsLeft[ 3 ].y = ACTOR_HEIGHT;
clipsLeft[ 3 ].w = ACTOR_WIDTH;
clipsLeft[ 3 ].h = ACTOR_HEIGHT;
clipsRight[0].x = 0;
clipsRight[0].y = ACTOR_HEIGHT *2;
clipsRight[0].w = ACTOR_WIDTH;
clipsRight[0].h = ACTOR_HEIGHT;
clipsRight[1].x = ACTOR_WIDTH;
clipsRight[1].y = ACTOR_HEIGHT *2;
clipsRight[1].w = ACTOR_WIDTH;
clipsRight[1].h = ACTOR_HEIGHT;
clipsRight[2].x = ACTOR_WIDTH * 2;
clipsRight[2].y = ACTOR_HEIGHT * 2;
clipsRight[2].w = ACTOR_WIDTH;
clipsRight[2].h = ACTOR_HEIGHT;
clipsRight[3].x = ACTOR_WIDTH * 3;
clipsRight[3].y = ACTOR_HEIGHT * 2;
clipsRight[3].w = ACTOR_WIDTH;
clipsRight[3].h = ACTOR_HEIGHT;
clipsUp[0].x = 0;
clipsUp[0].y = ACTOR_HEIGHT *3;
clipsUp[0].w = ACTOR_WIDTH;
clipsUp[0].h = ACTOR_HEIGHT;
clipsUp[1].x = ACTOR_WIDTH;
clipsUp[1].y = ACTOR_HEIGHT *3;
clipsUp[1].w = ACTOR_WIDTH;
clipsUp[1].h = ACTOR_HEIGHT;
clipsUp[2].x = ACTOR_WIDTH * 2;
clipsUp[2].y = ACTOR_HEIGHT *3;
clipsUp[2].w = ACTOR_WIDTH;
clipsUp[2].h = ACTOR_HEIGHT;
clipsUp[3].x = ACTOR_WIDTH * 3;
clipsUp[3].y = ACTOR_HEIGHT *3;
clipsUp[3].w = ACTOR_WIDTH;
clipsUp[3].h = ACTOR_HEIGHT;
//设置子弹精灵图
clipsBullet[0].x = 64;
clipsBullet[0].y = 0;
clipsBullet[0].w = BULLET_WIDTH;
clipsBullet[0].h = BULLET_HEIGHT;
clipsBullet[1].x = 192;
clipsBullet[1].y = 0;
clipsBullet[1].w = BULLET_WIDTH;
clipsBullet[1].h = BULLET_HEIGHT;
clipsBullet[2].x = 0;
clipsBullet[2].y = 0;
clipsBullet[2].w = BULLET_WIDTH;
clipsBullet[2].h = BULLET_HEIGHT;
clipsBullet[3].x = 128;
clipsBullet[3].y = 0;
clipsBullet[3].w = BULLET_WIDTH;
clipsBullet[3].h = BULLET_HEIGHT;
//设置敌人精灵图
clipsEnemy_Right[0].x = 0;
clipsEnemy_Right[0].y = 0;
clipsEnemy_Right[0].w = ENEMY_WIDTH;
clipsEnemy_Right[0].h = ENEMY_HEIGHT;
clipsEnemy_Right[1].x = ENEMY_WIDTH;
clipsEnemy_Right[1].y = 0;
clipsEnemy_Right[1].w = ENEMY_WIDTH;
clipsEnemy_Right[1].h = ENEMY_HEIGHT;
clipsEnemy_Right[2].x = ENEMY_WIDTH * 2;
clipsEnemy_Right[2].y = 0;
clipsEnemy_Right[2].w = ENEMY_WIDTH;
clipsEnemy_Right[2].h = ENEMY_HEIGHT;
clipsEnemy_Right[3].x = ENEMY_WIDTH * 3;
clipsEnemy_Right[3].y = 0;
clipsEnemy_Right[3].w = ENEMY_WIDTH;
clipsEnemy_Right[3].h = ENEMY_HEIGHT;
clipsEnemy_Left[0].x = 0;
clipsEnemy_Left[0].y = ENEMY_HEIGHT;
clipsEnemy_Left[0].w = ENEMY_WIDTH;
clipsEnemy_Left[0].h = ENEMY_HEIGHT;
clipsEnemy_Left[1].x = ENEMY_WIDTH;
clipsEnemy_Left[1].y = ENEMY_HEIGHT;
clipsEnemy_Left[1].w = ENEMY_WIDTH;
clipsEnemy_Left[1].h = ENEMY_HEIGHT;
clipsEnemy_Left[2].x = ENEMY_WIDTH * 2;
clipsEnemy_Left[2].y = ENEMY_HEIGHT;
clipsEnemy_Left[2].w = ENEMY_WIDTH;
clipsEnemy_Left[2].h = ENEMY_HEIGHT;
clipsEnemy_Left[3].x = ENEMY_WIDTH * 3;
clipsEnemy_Left[3].y = ENEMY_HEIGHT;
clipsEnemy_Left[3].w = ENEMY_WIDTH;
clipsEnemy_Left[3].h = ENEMY_HEIGHT;
}
#include "SDL/SDL_image.h"
#include <string>
//Screen attributes
const int SCREEN_WIDTH = 1024;
const int SCREEN_HEIGHT = 720;
const int SCREEN_BPP = 32;
//The frame rate
const int FRAMES_PER_SECOND = 10;
//The dot dimensions
const int ACTOR_WIDTH = 108;
const int ACTOR_HEIGHT = 116;
//子弹尺寸
const int BULLET_WIDTH = 64;
const int BULLET_HEIGHT = 64;
const int ENEMY_WIDTH = 128;
const int ENEMY_HEIGHT = 128;
const int ACTOR_RIGHT = 0;
const int ACTOR_LEFT = 1;
const int ACTOR_UP = 2;
const int ACTOR_DOWN = 3;
const int BULLET_RIGHT = 0;
const int BULLET_LEFT = 1;
const int BULLET_UP = 2;
const int BULLET_DOWN = 3;
//The dimensions of the level
const int LEVEL_WIDTH = 2380;
const int LEVEL_HEIGHT = 2320;
//The surfaces
SDL_Surface *actor = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *bullet = NULL;
SDL_Surface *enemy = NULL;
//The event structure
SDL_Event event;
SDL_Rect clipsRight[ 4 ];
SDL_Rect clipsLeft[ 4 ];
SDL_Rect clipsUp[ 4 ];
SDL_Rect clipsDown[ 4 ];
SDL_Rect clipsBullet[ 4 ];
SDL_Rect clipsEnemy_Right[ 4 ];
SDL_Rect clipsEnemy_Left[ 4 ];
SDL_Rect clipsEnemy_Up[ 4 ];
SDL_Rect clipsEnemy_Down[ 4 ];
SDL_Rect wall[100];
//The camera
SDL_Rect camera = { 800, 800, SCREEN_WIDTH, SCREEN_HEIGHT };
class Actor
{
private:
SDL_Rect box; //设置盒子
int xVel, yVel; //速度
int frame; //帧数
int status; //状态
public:
Actor();
void handle_input();
void move();
void show();
void set_camera();
};
class Bullet
{
private:
SDL_Rect bullet_box; //子弹的盒子
int bullet_xVel, bullet_yVel; //子弹速度
int bullet_status; //子弹形态
public:
Bullet();
void bullet_handle_input();
void move();
void bullet_show();
};
class Enemy
{
private:
SDL_Rect enemy_box; //设置盒子
int enemy_xVel, enemy_yVel; //速度
int enemy_frame; //帧数
int enemy_status; //状态
public:
Enemy();
void move();
void enemy_show();
};
void set_clips()
{
//设置人物精灵图
clipsDown[ 0 ].x = 0;
clipsDown[ 0 ].y = 0;
clipsDown[ 0 ].w = ACTOR_WIDTH;
clipsDown[ 0 ].h = ACTOR_HEIGHT;
clipsDown[ 1 ].x = ACTOR_WIDTH;
clipsDown[ 1 ].y = 0;
clipsDown[ 1 ].w = ACTOR_WIDTH;
clipsDown[ 1 ].h = ACTOR_HEIGHT;
clipsDown[ 2 ].x = ACTOR_WIDTH * 2;
clipsDown[ 2 ].y = 0;
clipsDown[ 2 ].w = ACTOR_WIDTH;
clipsDown[ 2 ].h = ACTOR_HEIGHT;
clipsDown[ 3 ].x = ACTOR_WIDTH * 3;
clipsDown[ 3 ].y = 0;
clipsDown[ 3 ].w = ACTOR_WIDTH;
clipsDown[ 3 ].h = ACTOR_HEIGHT;
clipsLeft[ 0 ].x = 0;
clipsLeft[ 0 ].y = ACTOR_HEIGHT;
clipsLeft[ 0 ].w = ACTOR_WIDTH;
clipsLeft[ 0 ].h = ACTOR_HEIGHT;
clipsLeft[ 1 ].x = ACTOR_WIDTH;
clipsLeft[ 1 ].y = ACTOR_HEIGHT;
clipsLeft[ 1 ].w = ACTOR_WIDTH;
clipsLeft[ 1 ].h = ACTOR_HEIGHT;
clipsLeft[ 2 ].x = ACTOR_WIDTH * 2;
clipsLeft[ 2 ].y = ACTOR_HEIGHT;
clipsLeft[ 2 ].w = ACTOR_WIDTH;
clipsLeft[ 2 ].h = ACTOR_HEIGHT;
clipsLeft[ 3 ].x = ACTOR_WIDTH * 3;
clipsLeft[ 3 ].y = ACTOR_HEIGHT;
clipsLeft[ 3 ].w = ACTOR_WIDTH;
clipsLeft[ 3 ].h = ACTOR_HEIGHT;
clipsRight[0].x = 0;
clipsRight[0].y = ACTOR_HEIGHT *2;
clipsRight[0].w = ACTOR_WIDTH;
clipsRight[0].h = ACTOR_HEIGHT;
clipsRight[1].x = ACTOR_WIDTH;
clipsRight[1].y = ACTOR_HEIGHT *2;
clipsRight[1].w = ACTOR_WIDTH;
clipsRight[1].h = ACTOR_HEIGHT;
clipsRight[2].x = ACTOR_WIDTH * 2;
clipsRight[2].y = ACTOR_HEIGHT * 2;
clipsRight[2].w = ACTOR_WIDTH;
clipsRight[2].h = ACTOR_HEIGHT;
clipsRight[3].x = ACTOR_WIDTH * 3;
clipsRight[3].y = ACTOR_HEIGHT * 2;
clipsRight[3].w = ACTOR_WIDTH;
clipsRight[3].h = ACTOR_HEIGHT;
clipsUp[0].x = 0;
clipsUp[0].y = ACTOR_HEIGHT *3;
clipsUp[0].w = ACTOR_WIDTH;
clipsUp[0].h = ACTOR_HEIGHT;
clipsUp[1].x = ACTOR_WIDTH;
clipsUp[1].y = ACTOR_HEIGHT *3;
clipsUp[1].w = ACTOR_WIDTH;
clipsUp[1].h = ACTOR_HEIGHT;
clipsUp[2].x = ACTOR_WIDTH * 2;
clipsUp[2].y = ACTOR_HEIGHT *3;
clipsUp[2].w = ACTOR_WIDTH;
clipsUp[2].h = ACTOR_HEIGHT;
clipsUp[3].x = ACTOR_WIDTH * 3;
clipsUp[3].y = ACTOR_HEIGHT *3;
clipsUp[3].w = ACTOR_WIDTH;
clipsUp[3].h = ACTOR_HEIGHT;
//设置子弹精灵图
clipsBullet[0].x = 64;
clipsBullet[0].y = 0;
clipsBullet[0].w = BULLET_WIDTH;
clipsBullet[0].h = BULLET_HEIGHT;
clipsBullet[1].x = 192;
clipsBullet[1].y = 0;
clipsBullet[1].w = BULLET_WIDTH;
clipsBullet[1].h = BULLET_HEIGHT;
clipsBullet[2].x = 0;
clipsBullet[2].y = 0;
clipsBullet[2].w = BULLET_WIDTH;
clipsBullet[2].h = BULLET_HEIGHT;
clipsBullet[3].x = 128;
clipsBullet[3].y = 0;
clipsBullet[3].w = BULLET_WIDTH;
clipsBullet[3].h = BULLET_HEIGHT;
//设置敌人精灵图
clipsEnemy_Right[0].x = 0;
clipsEnemy_Right[0].y = 0;
clipsEnemy_Right[0].w = ENEMY_WIDTH;
clipsEnemy_Right[0].h = ENEMY_HEIGHT;
clipsEnemy_Right[1].x = ENEMY_WIDTH;
clipsEnemy_Right[1].y = 0;
clipsEnemy_Right[1].w = ENEMY_WIDTH;
clipsEnemy_Right[1].h = ENEMY_HEIGHT;
clipsEnemy_Right[2].x = ENEMY_WIDTH * 2;
clipsEnemy_Right[2].y = 0;
clipsEnemy_Right[2].w = ENEMY_WIDTH;
clipsEnemy_Right[2].h = ENEMY_HEIGHT;
clipsEnemy_Right[3].x = ENEMY_WIDTH * 3;
clipsEnemy_Right[3].y = 0;
clipsEnemy_Right[3].w = ENEMY_WIDTH;
clipsEnemy_Right[3].h = ENEMY_HEIGHT;
clipsEnemy_Left[0].x = 0;
clipsEnemy_Left[0].y = ENEMY_HEIGHT;
clipsEnemy_Left[0].w = ENEMY_WIDTH;
clipsEnemy_Left[0].h = ENEMY_HEIGHT;
clipsEnemy_Left[1].x = ENEMY_WIDTH;
clipsEnemy_Left[1].y = ENEMY_HEIGHT;
clipsEnemy_Left[1].w = ENEMY_WIDTH;
clipsEnemy_Left[1].h = ENEMY_HEIGHT;
clipsEnemy_Left[2].x = ENEMY_WIDTH * 2;
clipsEnemy_Left[2].y = ENEMY_HEIGHT;
clipsEnemy_Left[2].w = ENEMY_WIDTH;
clipsEnemy_Left[2].h = ENEMY_HEIGHT;
clipsEnemy_Left[3].x = ENEMY_WIDTH * 3;
clipsEnemy_Left[3].y = ENEMY_HEIGHT;
clipsEnemy_Left[3].w = ENEMY_WIDTH;
clipsEnemy_Left[3].h = ENEMY_HEIGHT;
}