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

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