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

Last change on this file since 56 was 56, checked in by Sam Hocevar, 15 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 2.2 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 "mdlread.hpp"
16#include "video.hpp"
17#include "image.hpp"
18#include "palette.hpp"
19#include "linked.hpp"
20#include "glread.hpp"
21#include "gifread.hpp"
22#include "ppmread.hpp"
23#include "emm.hpp"
24#include "sprite.hpp"
25
26
27void sprite::restore_background()
28{ if (x+save->width()>=0 && y+save->height()>=0 && x<=xres && y<=yres)
29      save->put_image(screen,x,y); }
30
31void sprite::get_background()
32{ if (x+visual->width()>=0 && y+visual->height()>=0 && x<=xres && y<=yres)
33   screen->put_part(save,0,0,x,y,x+save->width()-1,y+save->height()-1); }
34
35void sprite::draw()
36{ if (x+visual->width()>=0 && y+visual->height()>=0 && x<=xres && y<=yres)
37   visual->put_image(screen,x,y,1); }
38
39sprite::sprite(image *Screen, image *Visual, int X, int Y)
40{
41  CHECK(Visual && Screen);
42  x=X; y=Y; visual=Visual; screen=Screen;
43  save=new image(visual->width(),visual->height());
44  get_background();
45} ;
46
47sprite::~sprite()
48{
49  delete save; 
50}
51
52void sprite_controller::add_sprite(sprite *sp)
53{ sprites.add_end((linked_node *)sp); }
54
55void sprite_controller::remove_sprites()
56{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->restore_background();); }
57
58void sprite_controller::put_sprites()
59{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->draw();); }
60
61void sprite_controller::get_backgrounds()
62{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->get_background();); }
63
64void sprite::change_visual(image *Visual, int delete_old)
65{ if (delete_old)
66    delete visual;
67  visual=Visual;
68  if (save->width()!=Visual->width() || save->height()!=Visual->height())
69  {
70    delete save;
71    save=new image(visual->width(),visual->height());
72  }
73  get_background();
74}
75
76void sprite_controller::bring_front(sprite *sp)
77{
78  ERROR(sprites.unlink((linked_node *)sp),"unlink failure");
79  sprites.add_end((linked_node *)sp);
80}
81
82void sprite_controller::delete_sprite(sprite *sp)
83{
84  ERROR(sprites.unlink((linked_node *)sp),"unlink failure");
85  delete sp;
86}
Note: See TracBrowser for help on using the repository browser.