Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL.h>
- #include "SDL_ttf.h"
- #include "SDL_gfxPrimitives.h"
- #include <vector>
- #include <map>
- #include <cmath>
- #include <algorithm>
- using namespace std;
- const int map_width = 640;
- const int map_height = 480;
- SDL_Surface* window = 0;
- const int window_width = 640;
- float deceleration = 0.99f;
- size_t ticks = 0;
- SDL_Color black = {0,0,0,255};
- SDL_Color white = {255,255,255,255};
- SDL_Color red = {255,0,0,255};
- SDL_Color green = {0,255,0,255};
- SDL_Color blue = {0,0,255,255};
- SDL_Color cyan = {0,255,255,255};
- SDL_Color magenta = {255,255,255,255};
- SDL_Color yellow = {255,255,0,255};
- float powerup_max_age = 9.0f;
- float explosion_max_radius = 0.5f;
- struct point
- {
- float a[2];
- point() { a[0] = a[1] = 0.0f; }
- point(float x, float y) { a[0] = x; a[1] = y; }
- float& operator[](int i) { return a[i]; }
- const float& operator[](int i) const { return a[i]; }
- };
- struct mob;
- struct world;
- struct ship;
- ///************************************************************************/
- /// SDL
- ///************************************************************************/
- struct SDLSystem
- {
- void init();
- void quit();
- size_t get_ticks();
- void clear_display(const SDL_Color& color);
- void draw_string(float x, float y, const SDL_Color& color, const char* format, ...);
- void draw_polygon(const point* p, int points, const SDL_Color& color);
- void draw_circle(const point& center, float radius, const SDL_Color& color);
- TTF_Font* font;
- };
- SDLSystem sdl;
- ///************************************************************************/
- /// Utilities
- ///************************************************************************/
- inline point vector_sum(const point& a, const point& b)
- {
- point v = point(a[0]+b[0], a[1]+b[1]);
- return v;
- }
- inline point vector_scale(const point& a, float factor)
- {
- point v = point(a[0]*factor, a[1]*factor);
- return v;
- }
- inline point vector_subtract(const point& a, const point& b)
- {
- point v = point(a[0]-b[0], a[1]-b[1]);
- return v;
- }
- inline float my_distance(const point& a, const point& b)
- {
- point v = vector_subtract(a,b);
- return sqrtf(v[0]*v[0]+v[1]*v[1]);
- }
- inline float deg2rad(float degs)
- {
- return degs*(3.1415926f/180.0f);
- }
- inline float rad2deg(float rads)
- {
- return rads*(180.0f/3.1415926f);
- }
- inline float calc_angle(const point& a, const point& b)
- {
- point p = vector_subtract(b,a);
- return rad2deg(atan2(p[0],p[1]));
- }
- inline point radial_point_from(const point& p, float radius, float angle)
- {
- angle = deg2rad(angle);
- return point(radius * sin(angle) + p[0], radius * cos(angle) + p[1]);
- }
- inline size_t get_ticks()
- {
- size_t t = ticks;
- ticks = sdl.get_ticks();
- return ticks - t;
- }
- inline float my_random()
- {
- return float(rand())/float(RAND_MAX);
- }
- inline float round(float r)
- {
- return (r > 0.0f) ? floor(r + 0.5f) : ceil(r - 0.5f);
- }
- ///************************************************************************/
- /// Timer
- ///************************************************************************/
- struct timer
- {
- float remaining;
- timer(float rem = 0) {
- remaining = rem; /// initarg seconds
- }
- bool done() const { return remaining <= 0; };
- void add_seconds(float sec) { remaining += sec; }
- void update_timer(float sec) { if (!done()) remaining -= sec; }
- };
- ///************************************************************************/
- /// Mob
- ///************************************************************************/
- struct mob
- {
- point pos;
- float radius;
- point velocity;
- bool dead;
- virtual ~mob() {}
- mob() {
- pos = point(0.5f, 0.5f);
- radius = 0;
- velocity = point(0.0f, 0.0f);
- dead = false;
- }
- virtual int type() const { return 'mob'; }
- virtual void collide(mob& other, world& world) {}
- point map_coords()
- {
- return point(round(pos[0]*map_width), round(pos[1]*map_height));
- }
- float map_radius() { return round(radius * map_width); }
- virtual void update(float delta, world& world)
- {
- pos = vector_sum(pos, vector_scale(velocity, delta));
- pos = point(fmod(pos[0]+100.0f,1.0f), fmod(pos[1]+100.0f,1.0f));
- }
- bool intersects_p(const mob& other)
- {
- return my_distance(pos,other.pos) < (other.radius + radius);
- }
- virtual void render()
- {
- /// ...
- }
- };
- ///************************************************************************/
- /// Asteroid
- ///************************************************************************/
- struct asteroid : mob
- {
- int size;
- float radii[20];
- float rotation;
- float facing;
- asteroid(const point& p = point(my_random(),my_random()), int s = 'big') {
- size = s;
- memset(radii, 0, sizeof(radii));
- rotation = (my_random()-0.5f)*5;
- facing = 0;
- pos = p;
- reset();
- }
- virtual ~asteroid() {}
- virtual int type() const { return 'ast'; }
- void reset();
- pair<mob*,mob*> break_down(world& world);
- virtual void update(float delta, world& world);
- virtual void render();
- };
- ///************************************************************************/
- /// Bullet
- ///************************************************************************/
- struct bullet : mob
- {
- ship* theship;
- bool super;
- bullet(const point& p, ship* sh) {
- radius = 0.005f;
- pos = p;
- theship = sh;
- super = false;
- }
- virtual void collide(mob& other, world& world);
- virtual void update(float delta, world& world);
- virtual void render();
- };
- ///************************************************************************/
- /// Explosion
- ///************************************************************************/
- struct explosion : mob
- {
- explosion(const point& p) {
- pos = p;
- radius = 0;
- }
- virtual void render();
- virtual void update(float delta, world& world);
- };
- ///************************************************************************/
- /// Powerup
- ///************************************************************************/
- struct powerup : mob
- {
- float age;
- powerup(const point& p) {
- pos = p;
- radius = 0.03f;
- age = 0;
- }
- virtual void update(float delta, world& world);
- virtual int type() const { return 'pwr'; }
- };
- ///************************************************************************/
- /// Bullet Powerup
- ///************************************************************************/
- struct bullet_powerup : powerup
- {
- bullet_powerup(const point& p) : powerup(p) {}
- virtual int type() const { return 'bpwr'; }
- virtual void render();
- };
- ///************************************************************************/
- /// Freeze Powerup
- ///************************************************************************/
- struct freeze_powerup : powerup
- {
- freeze_powerup(const point& p) : powerup(p) {}
- virtual int type() const { return 'fpwr'; }
- virtual void render();
- };
- ///************************************************************************/
- /// Shield Powerup
- ///************************************************************************/
- struct shield_powerup : powerup
- {
- shield_powerup(const point& p) : powerup(p) {}
- virtual void render();
- virtual int type() const { return 'spwr'; }
- };
- ///************************************************************************/
- /// Ship
- ///************************************************************************/
- struct ship : mob
- {
- map<int,timer> timers;
- point acceleration;
- float facing;
- ship() {
- facing = 0;
- radius = 0.04f;
- }
- virtual ~ship() {}
- virtual int type() const { return 'ship'; }
- virtual void update(float delta, world& world);
- virtual void collide(mob& other, world& world);
- void thrust_at(const point& coords)
- {
- acceleration = vector_sum(acceleration, vector_scale(vector_subtract(coords, pos), 0.03f));
- }
- void stop_thrust()
- {
- acceleration = point(0,0);
- }
- void shoot_at(const point& coords, world& world);
- bool shield_active_p();
- void add_shield(float seconds = 0);
- bool super_bullets_active_p();
- void add_super_bullets(float seconds = 0);
- virtual void render();
- };
- ///************************************************************************/
- /// World
- ///************************************************************************/
- struct world
- {
- vector<mob*> mobs;
- ship* theship;
- map<int,timer> timers;
- int level;
- int num_asteroids;
- int score;
- int max_level;
- int high_score;
- int lives;
- world() {
- theship = 0;
- level = 0;
- num_asteroids = 0;
- score = 0;
- max_level = 0;
- high_score = 0;
- lives = 0;
- }
- void start_next_level();
- bool level_cleared_p()
- {
- return num_asteroids < 1;
- }
- void after(int timer_name, float seconds, void(*func)(world&));
- static void static_next_level(world& world);
- static void static_respawn_sip(world& world);
- static bool is_zero(const mob* m) { return m==0; }
- void update_world(float delta);
- void render_world(bool paused);
- void add_score(int sc)
- {
- high_score = max(score += sc, high_score);
- }
- void add_score(const powerup& pwr)
- {
- add_score(level * 10);
- }
- void add_score(const asteroid& astr)
- {
- switch (astr.size)
- {
- case 'big': add_score(1); break;
- case 'med': add_score(2); break;
- case 'sm': add_score(5); break;
- }
- }
- ship* ship_moved(ship* sh);
- bullet* bullet_moved(bullet* b);
- void add_freeze(float seconds = 0);
- bool frozen_p();
- bool in_world(mob* mob);
- mob* add_to_world(mob* mob);
- void remove_from_world(mob* mob);
- };
- ///************************************************************************/
- /// random_powerup
- ///************************************************************************/
- powerup* random_powerup(const point& pos)
- {
- switch (rand()%3)
- {
- case 0: return new bullet_powerup(pos);
- case 1: return new freeze_powerup(pos);
- case 2: return new shield_powerup(pos);
- }
- return 0;
- }
- ///************************************************************************/
- /// main
- ///************************************************************************/
- int main(int argc, char *argv[])
- {
- sdl.init();
- int frame_rate = 60;
- sdl.clear_display(black);
- world* wrld = new world();
- bool paused = false, big_paused = false;
- SDL_Event event;
- bool quit = false;
- while (!quit)
- {
- while ( SDL_PollEvent(&event) )
- {
- switch (event.type) {
- case SDL_ACTIVEEVENT: {
- if ( event.active.state & SDL_APPACTIVE ) {
- if ( event.active.gain ) {
- big_paused = false;
- } else {
- big_paused = true;
- }
- }
- }
- break;
- case SDL_MOUSEBUTTONDOWN: {
- if (wrld->level > 0 && wrld->theship && !(big_paused || paused))
- {
- wrld->theship->shoot_at(point(float(event.button.x)/float(map_width), float(event.button.y/float(map_height))), *wrld);
- wrld->theship->thrust_at(point(float(event.button.x)/float(map_width), float(event.button.y)/float(map_height)));
- }
- }
- break;
- case SDL_MOUSEBUTTONUP: {
- if (wrld->level > 0 && wrld->theship)
- {
- wrld->theship->stop_thrust();
- }
- }
- break;
- case SDL_MOUSEMOTION: {
- if (wrld->theship)
- wrld->theship->facing = calc_angle(wrld->theship->pos, point(float(event.motion.x)/float(map_width), float(event.motion.y)/float(map_height)));
- }
- case SDL_KEYUP: {
- if (event.key.keysym.sym == SDLK_ESCAPE) quit = true;
- if (event.key.keysym.sym == SDLK_m) wrld->level = 0;
- if (event.key.keysym.sym == SDLK_p) {
- if (wrld->level == 0) /// start
- {
- wrld->score = 0;
- wrld->lives = 1;
- ticks = SDL_GetTicks();
- wrld->start_next_level();
- } else
- paused = !paused;
- }
- }
- break;
- case SDL_QUIT:
- quit = true;
- break;
- }
- }
- float delta = get_ticks()*0.001f;
- if (wrld->level > 0 && !(paused || big_paused))
- wrld->update_world(delta);
- wrld->render_world(paused || big_paused);
- SDL_Flip(window);
- }
- sdl.quit();
- return 0;
- }
- void SDLSystem::init()
- {
- SDL_Init(SDL_INIT_VIDEO);
- TTF_Init();
- window = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
- SDL_WM_SetCaption("ASTeroids", "ASTeroids");
- font = TTF_OpenFont("font.ttf", 18);
- }
- void SDLSystem::quit()
- {
- TTF_CloseFont(font);
- TTF_Quit();
- SDL_Quit();
- }
- size_t SDLSystem::get_ticks()
- {
- return SDL_GetTicks();
- }
- void SDLSystem::clear_display( const SDL_Color& color )
- {
- SDL_FillRect(window, 0, SDL_MapRGB(window->format, color.r, color.g, color.b));
- }
- void SDLSystem::draw_string( float x, float y, const SDL_Color& color, const char* format, ... )
- {
- va_list list;
- va_start(list,format);
- char buf[256];
- vsprintf(buf,format,list);
- SDL_Surface *text_surface;
- if(!(text_surface=TTF_RenderText_Solid(font,buf,color))) {
- } else {
- SDL_Rect dest = {x,y,100,100};
- SDL_BlitSurface(text_surface,NULL,window,&dest);
- SDL_FreeSurface(text_surface);
- }
- va_end(list);
- }
- void SDLSystem::draw_polygon( const point* p, int points, const SDL_Color& color )
- {
- vector<Sint16> px(points), py(points);
- for (int i=0; i<points; i++)
- {
- px[i] = Sint16(p[i][0]);
- py[i] = Sint16(p[i][1]);
- }
- polygonRGBA(window, &px[0], &py[0], points, color.r, color.g, color.b, color.unused);
- }
- void SDLSystem::draw_circle( const point& center, float radius, const SDL_Color& color )
- {
- circleRGBA (window, Sint16(center[0]), Sint16(center[1]), Sint16(radius), color.r, color.g, color.b, color.unused);
- }
- pair<mob*,mob*> asteroid::break_down( world& world )
- {
- if (size == 'sm')
- {
- /// gradually reduce the probability of powerups appearing
- if (my_random()*100.0f < 100.0f/(float(world.level)*0.3f+4.0f))
- return make_pair(random_powerup(pos),(mob*)0);
- else return make_pair((mob*)0, (mob*)0);
- } else
- {
- int smaller = (size=='big')?'med':'sm';
- return make_pair(new asteroid(pos, smaller), new asteroid(pos, smaller));
- }
- }
- void asteroid::reset()
- {
- float spd = 0;
- switch (size)
- {
- case 'big':
- radius = 0.1f;
- spd = 0.1f;
- break;
- case 'med':
- radius = 0.075f;
- spd = 0.15f;
- break;
- case 'sm':
- radius = 0.05f;
- spd = 0.25f;
- break;
- }
- for (int i=0; i<20; i++)
- radii[i] = (my_random()*0.2f+0.9f)*map_radius();
- velocity = point(my_random()*2*spd-spd, my_random()*2*spd-spd);
- }
- void asteroid::update( float delta, world& world )
- {
- if (!world.frozen_p())
- {
- facing += rotation;
- mob::update(delta, world);
- }
- }
- void asteroid::render()
- {
- point p[20];
- for (int i=0; i<20; i++)
- p[i] = radial_point_from(map_coords(), radii[i], facing+i*18);
- sdl.draw_polygon(p, 20, white);
- }
- void bullet::collide( mob& other, world& world )
- {
- if (other.type() == 'ast')
- {
- world.remove_from_world(&other);
- if (!super)
- world.remove_from_world(this);
- asteroid& ast = (asteroid&)other;
- pair<mob*,mob*> newmobs = ast.break_down(world);
- if (newmobs.first) world.add_to_world(newmobs.first);
- if (newmobs.second) world.add_to_world(newmobs.second);
- world.add_to_world(new explosion(ast.pos));
- world.add_score(ast);
- }
- }
- void bullet::update( float delta, world& world )
- {
- pos = vector_sum(pos, vector_scale(velocity, delta));
- if (pos[0] < 0 || pos[1] < 0 || pos[0] > map_width || pos[1] > map_height)
- world.remove_from_world(this);
- world.bullet_moved(this);
- }
- void bullet::render()
- {
- point coords = map_coords();
- float rad = map_radius();
- sdl.draw_circle(coords, rad, red);
- if (super)
- sdl.draw_circle(coords, rad+my_random()*3, magenta);
- }
- void explosion::render()
- {
- point coords = map_coords();
- float rad = map_radius();
- sdl.draw_circle(coords, rad, red);
- sdl.draw_circle(coords, rad+my_random()*3, red);
- }
- void explosion::update( float delta, world& world )
- {
- if ((radius += delta) > explosion_max_radius)
- world.remove_from_world(this);
- }
- void powerup::update( float delta, world& world )
- {
- age += delta;
- if (ceil(age) > powerup_max_age)
- world.remove_from_world(this);
- }
- void bullet_powerup::render()
- {
- point coords = map_coords();
- float rad = map_radius();
- sdl.draw_circle(coords, rad, magenta);
- sdl.draw_circle(coords, round(rad*0.3f), white);
- }
- void freeze_powerup::render()
- {
- point coords = map_coords();
- float rad = map_radius();
- sdl.draw_circle(coords, rad, cyan);
- point poly[12];
- for (int i=0; i<12; i++)
- poly[i] = radial_point_from(coords, round(((i%2)?0.2f:0.7f)*rad), i*30.0f);
- sdl.draw_polygon(poly,12,white);
- }
- void shield_powerup::render()
- {
- point coords = map_coords();
- float rad = map_radius();
- sdl.draw_circle(coords, rad, green);
- point poly[] = {
- radial_point_from(coords, round(rad*0.8f), 40),
- radial_point_from(coords, round(rad*0.8f), 0),
- radial_point_from(coords, round(rad*0.8f), -40),
- radial_point_from(coords, round(rad*0.8f), -135),
- radial_point_from(coords, round(rad*0.8f), 135),
- };
- sdl.draw_polygon(poly, 5, white);
- }
- void ship::update( float delta, world& world )
- {
- velocity = vector_scale(vector_sum(velocity,acceleration), deceleration);
- for (map<int,timer>::iterator it=timers.begin(); it != timers.end(); it++)
- it->second.update_timer(delta);
- mob::update(delta,world);
- world.ship_moved(this);
- }
- void ship::collide( mob& other, world& world )
- {
- if (other.type() == 'ast')
- {
- if (!shield_active_p())
- {
- world.add_to_world(new explosion(pos));
- world.lives--;
- world.remove_from_world(this);
- return;
- }
- }
- else if (other.type() == 'spwr')
- {
- add_shield(6);
- world.remove_from_world(&other);
- world.add_score((const powerup&)other);
- }
- else if (other.type() == 'bpwr')
- {
- add_super_bullets(6);
- world.remove_from_world(&other);
- world.add_score((const powerup&)other);
- }
- else if (other.type() == 'fpwr')
- {
- world.add_freeze(6);
- world.remove_from_world(&other);
- world.add_score((const powerup&)other);
- }
- }
- void ship::shoot_at( const point& coords, world& world )
- {
- bullet* b = new bullet(pos, this);
- b->velocity = vector_scale(vector_subtract(coords, b->pos), 3);
- if (super_bullets_active_p())
- b->super = true;
- world.add_to_world(b);
- }
- bool ship::shield_active_p()
- {
- return !timers['shld'].done();
- }
- void ship::add_shield( float seconds /*= 0*/ )
- {
- if (shield_active_p())
- timers['shld'].add_seconds(seconds);
- else
- timers['shld'] = timer(seconds);
- }
- bool ship::super_bullets_active_p()
- {
- return !timers['supb'].done();
- }
- void ship::add_super_bullets( float seconds /*= 0*/ )
- {
- if (shield_active_p())
- timers['supb'].add_seconds(seconds);
- else
- timers['supb'] = timer(seconds);
- }
- void ship::render()
- {
- point coords = map_coords();
- float rad = map_radius();
- point poly[] = {
- radial_point_from(coords, rad, facing),
- radial_point_from(coords, rad, facing-130),
- radial_point_from(coords, round(rad*0.5f), facing+180),
- radial_point_from(coords, rad, facing+130),
- };
- sdl.draw_polygon(poly, 4, white);
- if (shield_active_p())
- {
- sdl.draw_circle(coords, round(rad+my_random()*3), green);
- }
- }
- void world::start_next_level()
- {
- level++;
- max_level = max(level, max_level);
- for (size_t i=0; i<mobs.size(); i++)
- {
- if (theship != mobs[i])
- delete mobs[i];
- }
- mobs.clear();
- timers.clear();
- for (int i=0; i<level; i++)
- add_to_world(new asteroid());
- add_to_world(theship?theship:(new ship()));
- theship->add_shield(6);
- }
- void world::after( int timer_name, float seconds, void(*func)(world&) )
- {
- if (timers.count(timer_name))
- {
- if (timers[timer_name].done())
- {
- timers.erase(timer_name);
- if (func) func(*this);
- }
- } else
- {
- timers[timer_name] = timer(seconds);
- }
- }
- void world::static_next_level( world& world )
- {
- world.lives++;
- world.start_next_level();
- }
- void world::static_respawn_sip( world& world )
- {
- if (world.lives < 1)
- world.level = 0;
- else
- {
- world.theship = new ship();
- world.add_to_world(world.theship);
- world.theship->add_shield(6);
- }
- }
- void world::update_world( float delta )
- {
- for (map<int,timer>::iterator it = timers.begin(); it != timers.end(); it++)
- {
- it->second.update_timer(delta);
- }
- for (size_t i=0; i<mobs.size(); i++)
- if (!mobs[i]->dead)
- mobs[i]->update(delta, *this);
- /// C++ ONLY
- /// Delete the dead objects
- for (size_t i=0; i<mobs.size(); i++)
- if (mobs[i]->dead)
- {
- delete mobs[i];
- mobs[i] = 0;
- }
- mobs.erase(remove_if(mobs.begin(), mobs.end(), is_zero), mobs.end());
- /// END C++ ONLY
- /// start next level 3 seconds after clearing
- if (level_cleared_p())
- after('clrd', 3, static_next_level);
- if (!theship)
- after('deth', 3, static_respawn_sip);
- }
- void world::render_world( bool paused )
- {
- sdl.clear_display(black);
- /// hud
- sdl.draw_string(10, 10, green, "Level %i", level);
- sdl.draw_string(10, map_height-28, green, "Lives %i", lives);
- sdl.draw_string(map_width-127, map_height-28, green, "Score %i", score);
- sdl.draw_string(map_width-140, 10, green, "%s [M]enu", (level==0)?"[P]lay":"[P]ause");
- if (level == 0)
- {
- /// title screen
- sdl.draw_string(round((map_width-81)*0.5f), round((map_height-18)*0.25f), green, "ASTeroids");
- sdl.draw_string(round((map_width-171)*0.5f), round((map_height-18)*0.5f), green, "High score: %i", high_score);
- sdl.draw_string(round((map_width-135)*0.5f), round((map_height-18)*0.75f), green, "Max level: %i", max_level);
- } else
- {
- /// game world
- SDL_Rect clip = {0, 0, map_width, map_height};
- SDL_SetClipRect(window, &clip);
- for (size_t i=0; i<mobs.size(); i++)
- if (!mobs[i]->dead)
- mobs[i]->render();
- SDL_SetClipRect(window, 0);
- /// pause text
- if (paused)
- sdl.draw_string(round((map_width-54)*0.5f), round((map_width-18)*0.5f), green, "PAUSED");
- }
- }
- ship* world::ship_moved( ship* sh )
- {
- vector<mob*> checkmobs;
- for (size_t i=0; i<mobs.size(); i++)
- {
- if (!mobs[i]->dead && sh != mobs[i] && sh->intersects_p(*mobs[i]))
- checkmobs.push_back(mobs[i]);
- }
- for (size_t i=0; i<checkmobs.size(); i++)
- {
- sh->collide(*checkmobs[i], *this);
- if (!in_world(sh))
- return sh;
- }
- return 0;
- }
- bullet* world::bullet_moved( bullet* b )
- {
- if (b->dead) return 0;
- vector<mob*> checkmobs;
- for (size_t i=0; i<mobs.size(); i++)
- {
- if (!mobs[i]->dead && b != mobs[i] && b->intersects_p(*mobs[i]))
- checkmobs.push_back(mobs[i]);
- }
- for (size_t i=0; i<checkmobs.size(); i++)
- {
- b->collide(*checkmobs[i], *this);
- if (!in_world(b))
- return b;
- }
- return 0;
- }
- void world::add_freeze( float seconds /*= 0*/ )
- {
- if (frozen_p())
- timers['frz'].add_seconds(seconds);
- else
- timers['frz'] = timer(seconds);
- }
- bool world::frozen_p()
- {
- return !timers['frz'].done();
- }
- bool world::in_world( mob* m )
- {
- vector<mob*>::iterator it = find(mobs.begin(), mobs.end(), m);
- if (it == mobs.end()) return false;
- return !(*it)->dead;
- }
- mob* world::add_to_world( mob* m )
- {
- mobs.push_back(m);
- if (m->type() == 'ship')
- theship = (ship*)m;
- else if (m->type() == 'ast')
- num_asteroids++;
- return m;
- }
- void world::remove_from_world( mob* mob )
- {
- if (mob->type() == 'ast')
- num_asteroids--;
- mob->dead = true;
- if (mob == theship)
- theship = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement