-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
103 lines (80 loc) · 2.09 KB
/
Copy pathsketch.js
File metadata and controls
103 lines (80 loc) · 2.09 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
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
var towerImg, tower;
var doorImg, door, doorsGroup;
var climberImg, climber, climbersGroup;
var ghost, ghostImg;
var invisibleGroup;
var PLAY = 1;
var END = 0;
var gameState = 1;
function preload(){
towerImg = loadImage("tower.png");
doorImg = loadImage("door.png");
climberImg = loadImage("climber.png");
ghostImg = loadImage("ghost-standing.png");
spookySound = loadSound("spooky.wav");
}
function setup(){
createCanvas(600,600);
tower = createSprite(300,300);
tower.addImage("tower",towerImg);
tower.velocityY = 1;
ghost = createSprite(200,200,50,50);
ghost.scale = 0.3;
ghost.addImage("ghost", ghostImg);
doorsGroup = new Group();
climbersGroup = new Group();
invisibleGroup = new Group();
}
function draw(){
background(0);
if (gameState === PLAY) {
if(keyDown("left_arrow")){
ghost.x = ghost.x - 10;
}
if(keyDown("right_arrow")){
ghost.x = ghost.x + 10;
}
if(keyDown("space")){
ghost.velocityY = -10;
}
ghost.velocityY = ghost.velocityY + 0.8
if(tower.y > 400){
tower.y = 300
}
spawnDoors();
if(ghost.isTouching(climbersGroup)) {
ghost.velocityY = 0;
}
if (invisibleGroup.isTouching(ghost) || ghost.y > 600) {
gameState = END;
}
drawSprites();
}
if (gameState === END) {
fill("white");
text("YOU DIED, CONGRATS",220,300);
}
}
function spawnDoors() {
if (frameCount % 240 === 0) {
var door = createSprite(200, -50);
door.x = Math.round(random(120,400));
door.addImage(doorImg);
door.velocityY = 1;
door.lifetime = 800;
doorsGroup.add(door);
var climber = createSprite(200,10);
climber.x = door.x;
climber.addImage("sshhingg", climberImg);
climber.velocityY = 1;
climber.lifetime = 800;
climbersGroup.add(climber);
var invisible = createSprite(200,21,80,5);
invisible.velocityY = 1;
invisible.lifetime = 800;
invisible.x = door.x;
invisible.visible = false;
invisibleGroup.add(invisible);
ghost.depth = door.depth + 1;
}
}