source: abuse/tags/pd/macabuse/imlib/sprite.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.9 KB
RevLine 
[49]1#include "macs.hpp"
2#include "mdlread.hpp"
3#include "video.hpp"
4#include "image.hpp"
5#include "palette.hpp"
6#include "linked.hpp"
7#include <math.h>
8#include "glread.hpp"
9#include "gifread.hpp"
10#include "ppmread.hpp"
11#include "emm.hpp"
12#include "sprite.hpp"
13
14extern image *screen;
15
16void sprite::restore_background()
17{ if (x+save->width()>=0 && y+save->height()>=0 && x<=xres && y<=yres)
18      save->put_image(screen,x,y); }
19
20void sprite::get_background()
21{ if (x+visual->width()>=0 && y+visual->height()>=0 && x<=xres && y<=yres)
22   screen->put_part(save,0,0,x,y,x+save->width()-1,y+save->height()-1); }
23
24void sprite::draw()
25{ if (x+visual->width()>=0 && y+visual->height()>=0 && x<=xres && y<=yres)
26   visual->put_image(screen,x,y,1); }
27
28sprite::sprite(image *Screen, image *Visual, int X, int Y)
29{
30  CHECK(Visual && Screen);
31  x=X; y=Y; visual=Visual;
32  save=new image(visual->width(),visual->height());
33  get_background();
34} ;
35
36sprite::~sprite()
37{
38  delete save; 
39}
40
41void sprite_controller::add_sprite(sprite *sp)
42{ sprites.add_end((linked_node *)sp); }
43
44void sprite_controller::remove_sprites()
45{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->restore_background();); }
46
47void sprite_controller::put_sprites()
48{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->draw();); }
49
50void sprite_controller::get_backgrounds()
51{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->get_background();); }
52
53void sprite::change_visual(image *Visual, int delete_old)
54{ if (delete_old)
55    delete visual;
56  visual=Visual;
57  if (save->width()!=Visual->width() || save->height()!=Visual->height())
58  {
59    delete save;
60    save=new image(visual->width(),visual->height());
61  }
62  get_background();
63}
64
65void sprite_controller::bring_front(sprite *sp)
66{
67  ERROR(sprites.unlink((linked_node *)sp),"unlink failure");
68  sprites.add_end((linked_node *)sp);
69}
70
71void sprite_controller::delete_sprite(sprite *sp)
72{
73  ERROR(sprites.unlink((linked_node *)sp),"unlink failure");
74  delete sp;
75}
Note: See TracBrowser for help on using the repository browser.