source: abuse/trunk/src/imlib/sprite.cpp @ 524

Last change on this file since 524 was 524, checked in by Sam Hocevar, 11 years ago

core: Get rid of mostly useless headers, move endianness handling to
common.h (and rewrite functions so that they do not need the SDL headers)
and move a few functions out of sdlport's video.cpp. These functions
were in the original video.cpp (which reappears) and shouldn't be part
of the SDL port.

File size: 2.0 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
13#include <math.h>
14
15#include "common.h"
16
17#include "video.h"
18#include "image.h"
19#include "palette.h"
20#include "linked.h"
21#include "sprite.h"
22
23
24void sprite::restore_background()
25{ if (x+save->Size().x>=0 && y+save->Size().y>=0 && x<=xres && y<=yres)
26      save->put_image(screen,x,y); }
27
28void sprite::get_background()
29{ if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
30   screen->put_part(save,0,0,x,y,x+save->Size().x-1,y+save->Size().y-1); }
31
32void sprite::draw()
33{ if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
34   visual->put_image(screen,x,y,1); }
35
36sprite::sprite(image *Screen, image *Visual, int X, int Y)
37{
38  CHECK(Visual && Screen);
39  x=X; y=Y; visual=Visual; screen=Screen;
40  save = new image(visual->Size());
41  get_background();
42}
43
44sprite::~sprite()
45{
46  delete save;
47}
48
49void sprite_controller::add_sprite(sprite *sp)
50{ sprites.add_end(sp); }
51
52void sprite_controller::remove_sprites()
53{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->restore_background(); ); }
54
55void sprite_controller::put_sprites()
56{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->draw(); ); }
57
58void sprite_controller::get_backgrounds()
59{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->get_background(); ); }
60
61void sprite::change_visual(image *Visual, int delete_old)
62{ if (delete_old)
63    delete visual;
64  visual=Visual;
65  if (save->Size() != Visual->Size())
66  {
67    delete save;
68    save = new image(visual->Size());
69  }
70  get_background();
71}
72
73void sprite_controller::bring_front(sprite *sp)
74{
75  ERROR(sprites.unlink(sp),"unlink failure");
76  sprites.add_end(sp);
77}
78
79void sprite_controller::delete_sprite(sprite *sp)
80{
81  ERROR(sprites.unlink(sp),"unlink failure");
82  delete sp;
83}
Note: See TracBrowser for help on using the repository browser.