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