Skip to content
This repository was archived by the owner on Apr 27, 2024. It is now read-only.

Commit faf9381

Browse files
committed
stuff
1 parent 4c57ab4 commit faf9381

File tree

3 files changed

+55
-23
lines changed

3 files changed

+55
-23
lines changed

js/meteors/asteroid.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
class Asteroid{
2-
constructor(ctx,health,x,y,w,h,speed,dt){
2+
constructor(ctx,health,x,y,w,h,asteroid_image_url){
33
this.health = health;
44
this.destroyed = false;
55
this.ctx = ctx;
6-
this.image = document.getElementById("asteroid");
6+
this.image = new Image();
7+
this.image.src = asteroid_image_url;
78
this.explosion_images = []
89
for (var x=1;x<=27;x++){
910
var explosion_img = new Image();
@@ -14,8 +15,7 @@ class Asteroid{
1415
this.y = y;
1516
this.w = w;
1617
this.h = h;
17-
this.speed = speed;
18-
this.dt = dt;
18+
this.dt;
1919
}
2020
get draw(){
2121
this.reDraw();
@@ -39,20 +39,27 @@ class Asteroid{
3939

4040
var asteroids_at_once = 2
4141
var asteroids_thrown = 0
42-
42+
//meteorBrown_big1
4343
function createAsteroid(dt,score){
4444
if (dt){
4545
if (asteroids_thrown < 0){
4646
asteroids_thrown = 2;
4747
}
4848
if (asteroids_at_once > asteroids_thrown){
49+
random = Math.floor((Math.random() * 15));
4950
x = Math.floor((Math.random() * canvas.width) + 1);
5051
y = Math.floor((Math.random() * 60) * -1);
51-
asteroid = new Asteroid(ctx,100,undefined,undefined,50,50,undefined);
52+
if (random > 3){
53+
size = "small";
54+
asteroid = new Asteroid(ctx,100,undefined,undefined,50,50,"img/meteors/meteorBrown_small1.png");
55+
} else {
56+
size = "big";
57+
asteroid = new Asteroid(ctx,200,undefined,undefined,100,100,"img/meteors/meteorBrown_big1.png");
58+
}
5259
asteroid.x = x;
5360
asteroid.y = y;
5461
asteroid.speed = 150 + (score * 0.01);
55-
asteroids.push(asteroid);
62+
asteroids.push({"size":size,"object":asteroid,"x_speed":0,"y_speed":asteroid.speed});
5663
asteroids_thrown++;
5764
}
5865
asteroids_thrown -= asteroids_at_once * dt;

js/pickups/powerUp_pickup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PowerUp_pickup{
2020
this.y += this.dt * this.drop_speed;
2121
}
2222
}
23-
var powerUp_pickups_at_once = 0.5;
23+
var powerUp_pickups_at_once = 2;
2424
var powerUp_pickups_thrown = 10;
2525
var powerUp_pickups_thrown_reset = 10;
2626

js/scenes/game.js

+40-15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Game{
1010
this.homeButton = homeButton;
1111
this.dt = 0;
1212
this.show = false;
13+
this.ctx = document.getElementById("canvas").getContext("2d");
1314
}
1415
get draw(){
1516
this.reDraw();
@@ -76,31 +77,55 @@ class Game{
7677
this.replayButton.draw;
7778
}
7879
if (this.asteroids){
79-
for (var asteroid in this.asteroids){
80-
if (!this.asteroids[asteroid].destroyed){
81-
CollisionDetector.rect1 = this.asteroids[asteroid];
80+
for (var i in this.asteroids){
81+
var create_asteroids_in_end = []
82+
asteroid.draw;
83+
asteroid.x += this.asteroids[i].x_speed * this.dt;
84+
asteroid.y += this.asteroids[i].y_speed * this.dt;
85+
if (asteroid.y > canvas.height){
86+
if (this.health.health && !asteroid.destroyed) {
87+
this.health.health -= 1;
88+
}
89+
this.asteroids.splice(asteroid,1);
90+
}
91+
if (this.asteroids[i]){
92+
asteroid = this.asteroids[i].object;
93+
} else {
94+
asteroid = {"destroyed":true};
95+
}
96+
if (!asteroid.destroyed){
97+
CollisionDetector.rect1 = asteroid;
8298
for (var i in this.player.lasers){
8399
var laser = this.player.lasers[i];
84100
CollisionDetector.rect2 = laser;
85101
if (CollisionDetector.get_rect_rect_collision){
86-
this.asteroids[asteroid].health -= this.player.shoot_damage;
87-
if (this.asteroids[asteroid].health <= 0 && this.health.health){
102+
asteroid.health -= this.player.shoot_damage;
103+
if (asteroid.health <= 0 && this.health.health){
88104
this.score.score += 100;
89-
this.asteroids[asteroid].destroyed = true;
105+
asteroid.destroyed = true;
106+
} else {
107+
var small_asteroid = JSON.parse(JSON.stringify(asteroid));
108+
small_asteroid.w /= 2;
109+
small_asteroid.h /= 2;
110+
small_asteroid.health /= 2;
111+
small_asteroid.x = asteroid.x + (asteroid.w / 2);
112+
small_asteroid.y = asteroid.y
113+
var asteroid_1 = new Asteroid(this.ctx,100,30,30,50,50,"img/meteors/meteorBrown_small1.png")
114+
this.asteroids[i].object = asteroid_1;
115+
this.asteroids[i].object.y_speed = -300;
116+
//create_asteroids_in_end.push({"size":size,"object":asteroid_1,"x_speed":300,"y_speed":300})
90117
}
91118
this.player.lasers.splice(i,1);
92119
}
93120
}
94121
}
95-
asteroid = this.asteroids[asteroid];
96-
asteroid.draw;
97-
asteroid.y += asteroid.speed * this.dt;
98-
if (asteroid.y > canvas.height){
99-
if (this.health.health && !asteroid.destroyed) {
100-
this.health.health -= 1;
101-
}
102-
this.asteroids.splice(asteroid,1);
103-
}
122+
for (var i in create_asteroids_in_end){
123+
if (create_asteroids_in_end[i]){
124+
this.asteroids.push(create_asteroids_in_end[i]);
125+
console.log(this.asteroids);
126+
}
127+
create_asteroids_in_end = [];
128+
}
104129
}
105130
}
106131
createAsteroid(this.dt,score.score);

0 commit comments

Comments
 (0)