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

Last change on this file since 650 was 650, checked in by Sam Hocevar, 12 years ago

imlib: make some Image methods use vec2i.

File size: 2.2 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]5 *
6 *  This software was released into the Public Domain. As with most public
[555]7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
[56]9 */
10
[555]11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
[56]14
15#include <math.h>
16
[512]17#include "common.h"
18
[481]19#include "video.h"
20#include "image.h"
21#include "palette.h"
22#include "linked.h"
23#include "sprite.h"
[2]24
25
26void sprite::restore_background()
[512]27{ if (x+save->Size().x>=0 && y+save->Size().y>=0 && x<=xres && y<=yres)
[650]28      screen->PutImage(save, vec2i(x, y)); }
[2]29
[124]30void sprite::get_background()
[512]31{ if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
[644]32   save->PutPart(screen,0,0,x,y,x+save->Size().x-1,y+save->Size().y-1); }
[2]33
34void sprite::draw()
[512]35{ if (x+visual->Size().x>=0 && y+visual->Size().y>=0 && x<=xres && y<=yres)
[650]36   screen->PutImage(visual, vec2i(x, y), 1); }
[2]37
38sprite::sprite(image *Screen, image *Visual, int X, int Y)
39{
40  CHECK(Visual && Screen);
41  x=X; y=Y; visual=Visual; screen=Screen;
[513]42  save = new image(visual->Size());
[2]43  get_background();
[513]44}
[2]45
46sprite::~sprite()
47{
[124]48  delete save;
[2]49}
50
51void sprite_controller::add_sprite(sprite *sp)
[519]52{ sprites.add_end(sp); }
[2]53
[534]54#define loopt(type,controll,first,inside) { controll=(type *)(first); \
55  if (first) do { inside controll=(type *)(controll->Next()); } \
56  while (controll!=(type *)(first)); }
57
[2]58void sprite_controller::remove_sprites()
[494]59{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->restore_background(); ); }
[2]60
61void sprite_controller::put_sprites()
[494]62{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->draw(); ); }
[2]63
64void sprite_controller::get_backgrounds()
[494]65{ sprite *sp; loopt(sprite,sp,sprites.first(),sp->get_background(); ); }
[2]66
67void sprite::change_visual(image *Visual, int delete_old)
68{ if (delete_old)
69    delete visual;
70  visual=Visual;
[513]71  if (save->Size() != Visual->Size())
[2]72  {
73    delete save;
[513]74    save = new image(visual->Size());
[2]75  }
76  get_background();
77}
78
79void sprite_controller::bring_front(sprite *sp)
80{
[519]81  ERROR(sprites.unlink(sp),"unlink failure");
82  sprites.add_end(sp);
[2]83}
84
85void sprite_controller::delete_sprite(sprite *sp)
86{
[519]87  ERROR(sprites.unlink(sp),"unlink failure");
[2]88  delete sp;
89}
[534]90
Note: See TracBrowser for help on using the repository browser.