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