-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjetpack.c
88 lines (81 loc) · 1.63 KB
/
jetpack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>
#include "picList.h"
#include "jetpack.h"
void drawPack(struct jetPack *JP, struct list *LS)
{
al_draw_bitmap(LS -> image, JP -> x, JP -> y, 0);
}
void movePack(struct jetPack *JP)
{
JP -> y += JP -> speed;
if(JP -> y < JP -> topBound){ JP -> y = JP -> topBound; }
if(JP -> y > HEIGHT - JP -> height){ JP -> y = HEIGHT - JP -> height; }
}
void initPack(struct jetPack *JP, ALLEGRO_BITMAP * image)
{
JP -> x = 100;
JP -> topBound = 0;
JP -> y = HEIGHT/2;
JP -> accel = 0.08;
JP -> ID = PLAYER;
JP -> distance = 0;
JP -> lives = 3;
JP -> speed = 0;
JP -> image = image;
JP -> width = al_get_bitmap_width(image);
JP -> height = al_get_bitmap_height(image);
JP -> score = 1000;
}
void speedUpPack(struct jetPack *JP)
{
JP -> speed -= JP -> accel;
}
void slowDownPack(struct jetPack *JP)
{
JP -> speed += GRAVITY;
}
void packFlyUp(struct jetPack *JP)
{
if(JP -> y != JP -> topBound)
{
speedUpPack(JP);
movePack(JP);
}
else
{
JP -> speed = 0;
}
if(JP -> y != HEIGHT - JP -> height)
{
speedUpPack(JP);
movePack(JP);
}
else
{
JP -> speed = 0;
}
}
void packFlyDown(struct jetPack *JP)
{
if(JP -> y != HEIGHT - JP -> height)
{
slowDownPack(JP);
movePack(JP);
}
else
{
JP -> speed = 0;
}
if(JP -> y != JP -> topBound)
{
slowDownPack(JP);
movePack(JP);
}
else
{
JP -> speed = 0;
}
}