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

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

imlib: minor refactoring.

File size: 2.3 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, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <math.h>
16
17#include "common.h"
18
19#include "video.h"
20#include "image.h"
21#include "palette.h"
22#include "linked.h"
23#include "sprite.h"
24
25
26void sprite::restore_background()
27{ if (x+save->Size().x>=0 && y+save->Size().y>=0 && x<=xres && y<=yres)
28      screen->PutImage(save, vec2i(x, y)); }
29
30void sprite::get_background()
31{ if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
32   save->PutPart(screen,vec2i(0,0), vec2i(x,y), vec2i(x+save->Size().x,y+save->Size().y)); }
33
34void sprite::draw()
35{ if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
36   screen->PutImage(visual, vec2i(x, y), 1); }
37
38sprite::sprite(image *Screen, image *Visual, int X, int Y)
39{
40  CHECK(Visual && Screen);
41  x=X; y=Y; visual=Visual; screen=Screen;
42  save = new image(visual->Size());
43  get_background();
44}
45
46sprite::~sprite()
47{
48  delete save;
49}
50
51void sprite_controller::add_sprite(sprite *sp)
52{ sprites.add_end(sp); }
53
54#define loopt(type,controll,first,inside) { controll=(type *)(first); \
55  if (first) do { inside controll=(type *)(controll->Next()); } \
56  while (controll!=(type *)(first)); }
57
58void sprite_controller::remove_sprites()
59{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->restore_background(); ); }
60
61void sprite_controller::put_sprites()
62{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->draw(); ); }
63
64void sprite_controller::get_backgrounds()
65{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->get_background(); ); }
66
67void sprite::change_visual(image *Visual, int delete_old)
68{ if (delete_old)
69    delete visual;
70  visual=Visual;
71  if (save->Size() != Visual->Size())
72  {
73    delete save;
74    save = new image(visual->Size());
75  }
76  get_background();
77}
78
79void sprite_controller::bring_front(sprite *sp)
80{
81  ERROR(sprites.unlink(sp),"unlink failure");
82  sprites.add_end(sp);
83}
84
85void sprite_controller::delete_sprite(sprite *sp)
86{
87  ERROR(sprites.unlink(sp),"unlink failure");
88  delete sp;
89}
90
Note: See TracBrowser for help on using the repository browser.