-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.cb
109 lines (93 loc) · 2.62 KB
/
enemy.cb
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from native reference random;
class Enemy
{
//Init
//------------------------------------------------------------------------------------
function Start(game, posX, posY, lowestTier)
{
this.game = game;
this.speed = 2;
this.right = false;
this.posX = posX;
this.posY = posY;
this.lowestTier = lowestTier;
this.rect = [this.posX, this.posY, 55, 55];
this.leftmost = false;
this.rightmost = false;
image = LoadImage(b"assets\enemy.png");
this.sprite = LoadTextureFromImage(image);
UnloadImage(image);
}
//Destroy
//------------------------------------------------------------------------------------
function OnDestroy()
{
if this in this.game.enemies
{
this.game.enemies.remove(this);
}
}
//Main
//------------------------------------------------------------------------------------
function Update()
{
//Movement
if (this.right)
{
this.posX += this.speed;
}
else
{
this.posX -= this.speed;
}
//Bouncing
if (this.posX > GetScreenWidth() - 55 and this.rightmost)
{
this.game.SwitchEnemyDirection();
}
else if (this.posX < 0 and this.leftmost)
{
this.game.SwitchEnemyDirection();
}
//Shooting
if (this.lowestTier)
{
if random.randint(0, 1500) == 500
{
this.game.enemyBullets.append(EnemyBullet(this.game, this.posX, this.posY));
}
}
}
function Render()
{
screenWidth = GetScreenWidth();
DrawTexture(this.sprite, int(this.posX - this.sprite.width/2), int(this.posY - this.sprite.height/2), WHITE);
}
//Direction Switching
//------------------------------------------------------------------------------------
function SetLeftmost(value)
{
this.leftmost = value;
}
function SetRightmost(value)
{
this.rightmost = value;
}
function SwitchDirection()
{
this.right = not this.right;
}
//Collision
//------------------------------------------------------------------------------------
function CheckCollision(x, y) is bool
{
if (CheckCollisionPointRec((x, y), (this.posX - 27, this.posY - 30, 55, 55)))
{
return true;
}
else
{
return false;
}
}
}