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

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

style: remove trailing spaces, fix copyright statements.

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