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