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

Last change on this file since 512 was 512, checked in by Sam Hocevar, 8 years ago

imlib: use vec2i for image::size and unroll all necessary changes
everywhere else in the code.

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 "macs.h"
18#include "video.h"
19#include "image.h"
20#include "palette.h"
21#include "linked.h"
22#include "sprite.h"
23
24
25void sprite::restore_background()
26{ if (x+save->Size().x>=0 && y+save->Size().y>=0 && x<=xres && y<=yres)
27      save->put_image(screen,x,y); }
28
29void sprite::get_background()
30{ if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
31   screen->put_part(save,0,0,x,y,x+save->Size().x-1,y+save->Size().y-1); }
32
33void sprite::draw()
34{ if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
35   visual->put_image(screen,x,y,1); }
36
37sprite::sprite(image *Screen, image *Visual, int X, int Y)
38{
39  CHECK(Visual && Screen);
40  x=X; y=Y; visual=Visual; screen=Screen;
41  save=new image(visual->Size().x,visual->Size().y);
42  get_background();
43} ;
44
45sprite::~sprite()
46{
47  delete save;
48}
49
50void sprite_controller::add_sprite(sprite *sp)
51{ sprites.add_end((linked_node *)sp); }
52
53void sprite_controller::remove_sprites()
54{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->restore_background(); ); }
55
56void sprite_controller::put_sprites()
57{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->draw(); ); }
58
59void sprite_controller::get_backgrounds()
60{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->get_background(); ); }
61
62void sprite::change_visual(image *Visual, int delete_old)
63{ if (delete_old)
64    delete visual;
65  visual=Visual;
66  if (save->Size().x!=Visual->Size().x || save->Size().y!=Visual->Size().y)
67  {
68    delete save;
69    save=new image(visual->Size().x,visual->Size().y);
70  }
71  get_background();
72}
73
74void sprite_controller::bring_front(sprite *sp)
75{
76  ERROR(sprites.unlink((linked_node *)sp),"unlink failure");
77  sprites.add_end((linked_node *)sp);
78}
79
80void sprite_controller::delete_sprite(sprite *sp)
81{
82  ERROR(sprites.unlink((linked_node *)sp),"unlink failure");
83  delete sp;
84}
Note: See TracBrowser for help on using the repository browser.