网页
资讯
视频
图片
知道
文库
贴吧
地图
采购
进入贴吧
全吧搜索
吧内搜索
搜贴
搜人
进吧
搜标签
日
一
二
三
四
五
六
签到排名:今日本吧第
个签到,
本吧因你更精彩,明天继续来努力!
本吧签到人数:0
一键签到
成为超级会员,使用一键签到
一键签到
本月漏签
0
次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行
补签
。
连续签到:
天 累计签到:
天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
05月15日
漏签
0
天
sdl吧
关注:
4,209
贴子:
12,531
看贴
图片
吧主推荐
视频
游戏
38
回复贴,共
1
页
<<返回sdl吧
>0< 加载中...
新人求助!!!!
只看楼主
收藏
回复
chanchiuyeung
核心吧友
6
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
大一程序设计期末作业要求用SDL做一个小游戏,然后我在做一个类似孤胆枪手的,在处理发射子弹是有点问题。子弹发射后会这样...子弹运动和人物运动的代码都是类似的可是为什么只有子弹会出现这个问题。求解求解...
chanchiuyeung
核心吧友
6
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
#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;
}
2025-05-15 16:01:43
广告
chanchiuyeung
核心吧友
6
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
class Timer
{
private:
//The clock time when the timer started
int startTicks;
//The ticks stored when the timer was paused
int pausedTicks;
//The timer status
bool paused;
bool started;
public:
//Initializes variables
Timer();
//The various clock actions
void start();
void stop();
void pause();
void unpause();
//Gets the timer's time
int get_ticks();
//Checks the status of the timer
bool is_started();
bool is_paused();
};
SDL_Surface *load_image( std::string filename )
{
//The image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized surface that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized surface
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old surface
SDL_FreeSurface( loadedImage );
//If the surface was optimized
if( optimizedImage != NULL )
{
Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 255, 255,255 );
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
}
}
//Return the optimized surface
return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
//Holds offsets
SDL_Rect offset;
//Get offsets
offset.x = x;
offset.y = y;
//Blit
SDL_BlitSurface( source, clip, destination, &offset );
}
bool init()
{
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
//Set up the screen
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//If there was an error in setting up the screen
if( screen == NULL )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption( "Move the Actor", NULL );
//If everything initialized fine
return true;
}
bool load_files()
{
actor = load_image( "actor2.bmp" );
background = load_image( "background.png" );
bullet = load_image( "bullet.bmp");
if( actor == NULL )
{
return false;
}
if( background == NULL )
{
return false;
}
return true;
}
void clean_up()
{
SDL_FreeSurface( actor );
SDL_FreeSurface( background );
SDL_FreeSurface( bullet );
SDL_Quit();
}
bool check_collision( SDL_Rect A, SDL_Rect B )
{
//The sides of the rectangles
int leftA, leftB;
int rightA, rightB;
int topA, topB;
int bottomA, bottomB;
//Calculate the sides of rect A
leftA = A.x;
rightA = A.x + A.w;
topA = A.y;
bottomA = A.y + A.h;
//Calculate the sides of rect B
leftB = B.x;
rightB = B.x + B.w;
topB = B.y;
bottomB = B.y + B.h;
//If any of the sides from A are outside of B
if( bottomA <= topB )
{
return false;
}
if( topA >= bottomB )
{
return false;
}
if( rightA <= leftB )
{
return false;
}
if( leftA >= rightB )
{
return false;
}
//If none of the sides from A are outside B
return true;
}
Actor::Actor()
{
//Initialize the offsets
box.x = 900;
box.y = 600;
//Initialize the velocity
xVel = 0;
yVel = 0;
box.w = ACTOR_WIDTH;
box.h = ACTOR_HEIGHT;
//Initialize movement variables
frame = 0;
//Initialize animation variables
status = ACTOR_RIGHT;
}
Bullet::Bullet()
{
//子弹起始位置跟随人物
bullet_box.x = 600;
bullet_box.y = 900;
//子弹速度
bullet_xVel = 0;
bullet_yVel = 0;
//初始化子弹尺寸
bullet_box.w = BULLET_WIDTH;
bullet_box.h = BULLET_HEIGHT;
}
void Bullet::bullet_handle_input()
{
if( event.type == SDL_KEYDOWN )
{
if( (event.key.keysym.sym == SDLK_i))
{
bullet_yVel = -20;
}
else if( (event.key.keysym.sym == SDLK_j) )
{
bullet_xVel = -20;
}
else if( (event.key.keysym.sym == SDLK_k) )
{
bullet_yVel = 20;
}
else if( (event.key.keysym.sym == SDLK_l) )
{
bullet_xVel = 20;
}
}
}
void Bullet::move()
{
bullet_box.x += bullet_xVel;
int i;
for(i=0; i<100; i++)
{
//If the dot went too far to the left or right
if( ( bullet_box.x < 0 ) || ( bullet_box.x + BULLET_WIDTH > LEVEL_WIDTH )|| ( check_collision( bullet_box, wall[i] ) ) )
{
//move back
bullet_box.x -= bullet_xVel;
}
}
//Move the dot up or down
bullet_box.y += bullet_yVel;
for(i=0; i<100; i++)
{
//If the dot went too far up or down
if( ( bullet_box.y < 0 ) || ( bullet_box.y + BULLET_HEIGHT > LEVEL_HEIGHT )|| ( check_collision( bullet_box, wall[i] ) ) )
{
//move back
bullet_box.y -= bullet_yVel;
}
}
}
void Bullet::bullet_show()
{
if( bullet_xVel < 0 )
{
//Set the animation to left
bullet_status = BULLET_LEFT;
}
//If Foo is moving right
else if( bullet_xVel > 0 )
{
//Set the animation to right
bullet_status = BULLET_RIGHT;
}
else if( bullet_yVel >0)
{
bullet_status = BULLET_DOWN;
}
else if( bullet_yVel <0)
{
bullet_status = BULLET_UP;
}
//Show the stick figure
if( bullet_status == BULLET_RIGHT )
{
apply_surface( bullet_box.x, bullet_box.y, bullet, background, &clipsBullet[ 0 ] );
}
else if( bullet_status == BULLET_LEFT )
{
apply_surface( bullet_box.x, bullet_box.y, bullet, background, &clipsBullet[ 1 ] );
}
else if( bullet_status == BULLET_UP )
{
apply_surface( bullet_box.x, bullet_box.y, bullet, background, &clipsBullet[ 2 ] );
}
else if( bullet_status == BULLET_DOWN )
{
apply_surface( bullet_box.x, bullet_box.y, bullet, background, &clipsBullet[ 3 ] );
}
}
void Actor::handle_input()
{
//If a key was pressed
if( event.type == SDL_KEYDOWN )
{
//Adjust the velocity
switch( event.key.keysym.sym )
{
case SDLK_w:
yVel -= ACTOR_HEIGHT / 4;
break;
case SDLK_s:
yVel += ACTOR_HEIGHT / 4;
break;
case SDLK_a:
xVel -= ACTOR_WIDTH / 4;
break;
case SDLK_d:
xVel += ACTOR_WIDTH / 4;
break;
}
}
//If a key was released
else if( event.type == SDL_KEYUP )
{
//Adjust the velocity
switch( event.key.keysym.sym )
{
case SDLK_w:
yVel += ACTOR_HEIGHT / 4;
break;
case SDLK_s:
yVel -= ACTOR_HEIGHT / 4;
break;
case SDLK_a:
xVel += ACTOR_WIDTH / 4;
break;
case SDLK_d:
xVel -= ACTOR_WIDTH / 4;
break;
}
}
}
void Actor::move()
{
//Move the dot left or right
box.x += xVel;
int i;
for(i=0; i<100; i++)
{
//If the dot went too far to the left or right
if( ( box.x < 0 ) || ( box.x + ACTOR_WIDTH > LEVEL_WIDTH )|| ( check_collision( box, wall[i] ) ) )
{
//move back
box.x -= xVel;
}
}
//Move the dot up or down
box.y += yVel;
for(i=0; i<100; i++)
{
//If the dot went too far up or down
if( ( box.y < 0 ) || ( box.y + ACTOR_HEIGHT > LEVEL_HEIGHT )|| ( check_collision( box, wall[i] ) ) )
{
//move back
box.y -= yVel;
}
}
}
chanchiuyeung
核心吧友
6
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
void Actor::show()
{
//If Foo is moving left
if( xVel < 0 )
{
//Set the animation to left
status = ACTOR_LEFT;
//Move to the next frame in the animation
frame++;
}
//If Foo is moving right
else if( xVel > 0 )
{
//Set the animation to right
status = ACTOR_RIGHT;
//Move to the next frame in the animation
frame++;
}
else if( yVel >0)
{
status = ACTOR_DOWN;
frame++;
}
else if( yVel <0)
{
status = ACTOR_UP;
frame++;
}
//If Foo standing
else
{
//Restart the animation
frame = 0;
}
//Loop the animation
if( frame >= 4 )
{
frame = 0;
}
//Show the stick figure
if( status == ACTOR_RIGHT )
{
apply_surface( box.x - camera.x, box.y - camera.y, actor, screen, &clipsRight[ frame ] );
}
else if( status == ACTOR_LEFT )
{
apply_surface( box.x - camera.x, box.y - camera.y, actor, screen, &clipsLeft[ frame ] );
}
else if( status == ACTOR_UP )
{
apply_surface( box.x - camera.x, box.y - camera.y, actor, screen, &clipsUp[ frame ] );
}
else if( status == ACTOR_DOWN )
{
apply_surface( box.x - camera.x, box.y - camera.y, actor, screen, &clipsDown[ frame ] );
}
}
void Actor::set_camera()
{
//Center the camera over the dot
camera.x = ( box.x + ACTOR_WIDTH / 2 ) - SCREEN_WIDTH / 2;
camera.y = ( box.y + ACTOR_HEIGHT / 2 ) - SCREEN_HEIGHT / 2;
//Keep the camera in bounds.
if( camera.x < 0 )
{
camera.x = 0;
}
if( camera.y < 0 )
{
camera.y = 0;
}
if( camera.x > LEVEL_WIDTH - camera.w )
{
camera.x = LEVEL_WIDTH - camera.w;
}
if( camera.y > LEVEL_HEIGHT - camera.h )
{
camera.y = LEVEL_HEIGHT - camera.h;
}
}
Timer::Timer()
{
//Initialize the variables
startTicks = 0;
pausedTicks = 0;
paused = false;
started = false;
}
void Timer::start()
{
//Start the timer
started = true;
//Unpause the timer
paused = false;
//Get the current clock time
startTicks = SDL_GetTicks();
}
void Timer::stop()
{
//Stop the timer
started = false;
//Unpause the timer
paused = false;
}
void Timer::pause()
{
//If the timer is running and isn't already paused
if( ( started == true ) && ( paused == false ) )
{
//Pause the timer
paused = true;
//Calculate the paused ticks
pausedTicks = SDL_GetTicks() - startTicks;
}
}
void Timer::unpause()
{
//If the timer is paused
if( paused == true )
{
//Unpause the timer
paused = false;
//Reset the starting ticks
startTicks = SDL_GetTicks() - pausedTicks;
//Reset the paused ticks
pausedTicks = 0;
}
}
int Timer::get_ticks()
{
//If the timer is running
if( started == true )
{
//If the timer is paused
if( paused == true )
{
//Return the number of ticks when the timer was paused
return pausedTicks;
}
else
{
//Return the current time minus the start time
return SDL_GetTicks() - startTicks;
}
}
//If the timer isn't running
return 0;
}
bool Timer::is_started()
{
return started;
}
bool Timer::is_paused()
{
return paused;
}
chanchiuyeung
核心吧友
6
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
int main( int argc, char* args[] )
{
//Quit flag
bool quit = false;
//The dot
Actor myActor;
Bullet myBullet;
wall[0].x = 0;
wall[0].y = 1235;
wall[0].w = 31;
wall[0].h = 10;
wall[1].x = 33;
wall[1].y = 1236-130;
wall[1].w = 29;
wall[1].h = 34;
wall[2].x = 65;
wall[2].y = 1122-40;
wall[2].w = 69;
wall[2].h = 124;
wall[3].x = 130;
wall[3].y = 981-40;
wall[3].w = 32;
wall[3].h = 167;
wall[4].x = 150;
wall[4].y = 700-40;
wall[4].w = 74;
wall[4].h = 280;
wall[5].x = 221;
wall[5].y = 491-40;
wall[5].w = 151;
wall[5].h = 230;
wall[6].x = 410;
wall[6].y = 720;
wall[6].w = 40;
wall[6].h = 5;
wall[7].x = 390;
wall[7].y = 435;
wall[7].w = 201;
wall[7].h = 10;
wall[8].x = 395;
wall[8].y = 100;
wall[8].w = 319;
wall[8].h = 80;
wall[9].x = 466;
wall[9].y = 70;
wall[9].w = 584;
wall[9].h = 120;
wall[10].x = 570;
wall[10].y = 103;
wall[10].w = 149;
wall[10].h = 240;
wall[11].x = 1015;
wall[11].y = 158;
wall[11].w = 154;
wall[11].h = 20;
wall[12].x = 1062;
wall[12].y = 213;
wall[12].w = 134;
wall[12].h = 20;
wall[13].x = 1159;
wall[13].y = 255;
wall[13].w = 56;
wall[13].h = 60;
wall[14].x = 1221;
wall[14].y = 283;
wall[14].w = 10;
wall[14].h = 1;
wall[15].x = 1400;
wall[15].y = 85;
wall[15].w = 175;
wall[15].h = 5;
wall[16].x = 2042;
wall[16].y = 50;
wall[16].w = 122;
wall[16].h = 50;
wall[17].x = 1818;
wall[17].y = 117;
wall[17].w = 246;
wall[17].h = 20;
wall[18].x = 1430;
wall[18].y = 356;
wall[18].w = 250;
wall[18].h = 1;
wall[19].x = 1550;
wall[19].y = 413;
wall[19].w = 211;
wall[19].h = 1;
wall[20].x = 1822;
wall[20].y = 468;
wall[20].w = 49;
wall[20].h = 10;
wall[21].x = 1882;
wall[21].y = 520;
wall[21].w = 27;
wall[21].h = 10;
wall[22].x = 1940;
wall[22].y = 593;
wall[22].w = 25;
wall[22].h = 60;
/*wall[23].x = 2200;
wall[23].y = 726;
wall[23].w = 13;
wall[23].h = 70;*/
wall[24].x = 2022;
wall[24].y = 793;
wall[24].w = 22;
wall[24].h = 20;
wall[25].x = 2000;
wall[25].y = 747;
wall[25].w = 36;
wall[25].h = 10;
wall[26].x = 1986;
wall[26].y = 700;
wall[26].w = 21;
wall[26].h = 33;
wall[27].x = 2060;
wall[27].y = 872;
wall[27].w = 29;
wall[27].h = 10;
wall[28].x = 2150;
wall[28].y = 973;
wall[28].w = 23;
wall[28].h = 5;
wall[29].x = 2118;
wall[29].y = 937;
wall[29].w = 53;
wall[29].h = 53;
wall[31].x = 2216;
wall[31].y = 1000;
wall[31].w = 10;
wall[31].h = 67;
wall[32].x = 2215;
wall[32].y = 1242;
wall[32].w = 20;
wall[32].h = 300;
wall[33].x = 2196;
wall[33].y = 1073;
wall[33].w = 51;
wall[33].h = 76;
wall[34].x = 1985;
wall[34].y = 1680;
wall[34].w = 32;
wall[34].h = 1;
wall[35].x = 2288;
wall[35].y = 1192;
wall[35].w = 91;
wall[35].h = 30;
wall[36].x = 2122;
wall[36].y = 1568;
wall[36].w = 61;
wall[36].h = 40;
wall[37].x = 2054;
wall[37].y = 1629;
wall[37].w = 64;
wall[37].h = 40;
wall[38].x = 1800;
wall[38].y = 1978;
wall[38].w = 623;
wall[38].h = 339;
wall[39].x = 1382;
wall[39].y = 2146;
wall[39].w = 487;
wall[39].h = 171;
wall[40].x = 1190;
wall[40].y = 2230;
wall[40].w = 20;
wall[40].h = 87;
wall[41].x = 10;
wall[41].y = 1889;
wall[41].w = 92;
wall[41].h = 238;
wall[42].x = 0;
wall[42].y = 1600;
wall[42].w = 99;
wall[42].h = 155;
wall[43].x = 890;
wall[43].y = 983;
wall[43].w = 324;
wall[43].h = 472;
wall[44].x = 1146;
wall[44].y = 1474;
wall[44].w = 153;
wall[44].h = 129;
wall[45].x = 1300;
wall[45].y = 1327;
wall[45].w = 216;
wall[45].h = 91;
wall[46].x = 1360;
wall[46].y = 1090;
wall[46].w = 145;
wall[46].h = 97;
wall[47].x = 1427;
wall[47].y = 1427;
wall[47].w = 90;
wall[47].h = 39;
wall[48].x = 1267;
wall[48].y = 1182;
wall[48].w = 68;
wall[48].h = 156;
//The frame rate regulator
Timer fps;
set_clips();
//Initialize
if( init() == false )
{
return 1;
}
//Load the files
if( load_files() == false )
{
return 1;
}
//While the user hasn't quit
while( quit == false )
{
//Start the frame timer
fps.start();
//While there's events to handle
while( SDL_PollEvent( &event ) )
{
//Handle events for the dot
myActor.handle_input();
myBullet.bullet_handle_input();
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
//Move the dot
myActor.move();
myBullet.move();
//Set the camera
myActor.set_camera();
//Show the background
apply_surface( 0, 0, background, screen, &camera );
//Show the dot on the screen
myActor.show();
myBullet.bullet_show();
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
if( SDL_Flip( background ) == -1 )
{
return 1;
}
//Cap the frame rate
if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
{
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
}
}
//Clean up
clean_up();
return 0;
}
chanchiuyeung
核心吧友
6
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
@一周休七日
chanchiuyeung
核心吧友
6
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
我想让子弹坐标跟随人物坐标
楪祈
活跃吧友
5
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
楼主方便把这个游戏的压缩包发给我么
2025-05-15 15:55:43
广告
楪祈
活跃吧友
5
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
小牛_牛sky
人气楷模
13
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
你是哪个学校的,还学SDL???
天才巧媳妇儿
活跃吧友
4
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
楼主,我想学sdl,新手,10成的,会c,c加加,你看看能不能教教我
贴吧用户_0EAM146
知名人士
10
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
感觉挺流弊
楪祈
活跃吧友
5
该楼层疑似违规已被系统折叠
隐藏此楼
查看此楼
超扬
登录百度账号
扫二维码下载贴吧客户端
下载贴吧APP
看高清直播、视频!
贴吧页面意见反馈
违规贴吧举报反馈通道
贴吧违规信息处理公示