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

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

imlib: remove a lot of dead code, especially from the linked list and
the WAV reader.

File size: 2.2 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
52#define loopt(type,controll,first,inside) { controll=(type *)(first); \
53  if (first) do { inside controll=(type *)(controll->Next()); } \
54  while (controll!=(type *)(first)); }
55
56void sprite_controller::remove_sprites()
57{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->restore_background(); ); }
58
59void sprite_controller::put_sprites()
60{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->draw(); ); }
61
62void sprite_controller::get_backgrounds()
63{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->get_background(); ); }
64
65void sprite::change_visual(image *Visual, int delete_old)
66{ if (delete_old)
67    delete visual;
68  visual=Visual;
69  if (save->Size() != Visual->Size())
70  {
71    delete save;
72    save = new image(visual->Size());
73  }
74  get_background();
75}
76
77void sprite_controller::bring_front(sprite *sp)
78{
79  ERROR(sprites.unlink(sp),"unlink failure");
80  sprites.add_end(sp);
81}
82
83void sprite_controller::delete_sprite(sprite *sp)
84{
85  ERROR(sprites.unlink(sp),"unlink failure");
86  delete sp;
87}
88
Note: See TracBrowser for help on using the repository browser.