-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.js
More file actions
67 lines (60 loc) · 1.56 KB
/
game.js
File metadata and controls
67 lines (60 loc) · 1.56 KB
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
var player
var line_space = 40
var field_min_radius = 200
var field_radius_limit = 1000
var field_shrink_rate = 0.2
var x_min = -1000, x_max = 1000
var y_min = -1000, y_max = 1000
var projectiles = []
function setup() {
createCanvas(windowWidth, windowHeight)
player = new Player()
}
function draw() {
if (mouseIsPressed) player.shoot();
field_radius_limit = max(field_min_radius, field_radius_limit-field_shrink_rate)
background(0, 0, 0)
translate(width/2-player.pos.x, height/2-player.pos.y)
draw_field_borders()
draw_background_lines()
draw_projectiles(projectiles)
player.update_going_direction(keyIsDown(87), keyIsDown(83), keyIsDown(65), keyIsDown(68))
player.update()
player.show()
}
function draw_projectiles(projectiles) {
for (var i = projectiles.length-1; i >= 0; i--) {
var projectile = projectiles[i]
if (projectile.alive === 0) {
projectiles.splice(i, 1)
}
else {
projectile.update()
projectile.show()
}
}
}
function add_projectile(projectile) {
projectiles.push(projectile)
}
function draw_field_borders() {
push()
translate(0,0)
stroke(255,0,0)
strokeWeight(10)
fill(230, 255, 255)
ellipse(0, 0, 2*field_radius_limit, 2*field_radius_limit)
pop()
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function draw_background_lines() {
stroke(0, 100)
strokeWeight(2)
push()
translate(0,0)
for (var i = x_min; i <= x_max; i+=line_space) line(i, y_min, i, y_max);
for (var i = y_min; i <= y_max; i+=line_space) line(x_min, i, x_max, i);
pop()
}