186 lines
3.5 KiB
JavaScript
186 lines
3.5 KiB
JavaScript
gameobject.elasticity = 1;
|
|
|
|
gameobject.clone("ball", {
|
|
collider: circle2d.clone(),
|
|
img: sprite.clone(),
|
|
phys: 0,
|
|
elasticity: 1,
|
|
friction: 0,
|
|
|
|
collide(hit) {
|
|
Sound.play("bump.wav");
|
|
},
|
|
|
|
start() {
|
|
this.velocity = [-10,-300];
|
|
Player.players[0].control(this);
|
|
},
|
|
|
|
input_left_down() {
|
|
/* Slow down */
|
|
},
|
|
|
|
input_right_down() {
|
|
/* Speed up */
|
|
},
|
|
});
|
|
|
|
Color.Gameboy = {
|
|
darkest: [15,56,15],
|
|
dark: [48,98,48],
|
|
light: [139,172,15],
|
|
lightest: [155,188,15]
|
|
};
|
|
|
|
Color.Rainbow = {
|
|
red: [204,0,1],
|
|
orange: [255,102,0],
|
|
darkorange: [205,102,1],
|
|
yellow: [205,204,0],
|
|
green: [0,153,1],
|
|
blue: [53,51,255]
|
|
};
|
|
|
|
gameobject.clone("brick", {
|
|
collider: polygon2d.clone(),
|
|
char: char2d.clone({
|
|
flash:Resources.load("brick.png"),
|
|
}),
|
|
|
|
start() {
|
|
this.char.stop();
|
|
this.flash();
|
|
this.timer = timer.make(() => {
|
|
this.flash();
|
|
this.timer.time = Math.random_range(2,10);
|
|
}, Math.random_range(2,10));
|
|
|
|
this.char.color = Color.Rainbow.red;
|
|
},
|
|
|
|
flash() {
|
|
this.char.play("flash");
|
|
},
|
|
|
|
collide(hit) {
|
|
if (hit.obj.from !== 'ball')
|
|
return;
|
|
|
|
this.powerup?.();
|
|
this.timer.kill();
|
|
this.kill();
|
|
},
|
|
});
|
|
|
|
var act_x = Action.add_new("move");
|
|
act_x.inputs.push("axis_ljoy");
|
|
|
|
var paddle = gameobject.clone("paddle", {
|
|
collider: polygon2d.clone(),
|
|
img: sprite.clone(),
|
|
phys: 1,
|
|
elasticity: 1,
|
|
|
|
speed: 1000,
|
|
|
|
length: 50,
|
|
height: 28,
|
|
lengths: [16,24,32,40,48],
|
|
growlvl: 1,
|
|
maxgrow: 5,
|
|
max_x: 0,
|
|
extents: 300,
|
|
|
|
input_larrow_down() { this.input_a_down(); },
|
|
|
|
frame_vel: [0,0],
|
|
|
|
input_a_down() {
|
|
this.frame_vel = this.frame_vel.add([-1,0]);
|
|
},
|
|
|
|
input_d_down() {
|
|
this.frame_vel = this.frame_vel.add([1,0]);
|
|
},
|
|
|
|
update(dt) {
|
|
this.angle = 0;
|
|
var fpos = this.pos;
|
|
fpos.x += this.frame_vel.x * this.speed * dt;
|
|
fpos.x = Math.clamp(fpos.x,-this.max_x,this.max_x);
|
|
this.pos = fpos;
|
|
this.frame_vel = [0,0];
|
|
},
|
|
|
|
physupdate(dt) { this.velocity = [0,0]; },
|
|
|
|
gamepad_ljoy_axis(v) {
|
|
v[1] = 0;
|
|
this.pos = this.pos.add(v.scale(this.speed*Yugine.dt));
|
|
},
|
|
|
|
setup() {
|
|
Player.players[0].control(this);
|
|
this.length = this.lengths[0];
|
|
},
|
|
|
|
input_p_pressed() { this.grow(); },
|
|
input_l_pressed() { Gamestate.spawnball(); },
|
|
|
|
grow() {
|
|
this.setgrow(this.growlvl + 1);
|
|
},
|
|
|
|
setgrow(n) {
|
|
this.growlvl = Math.clamp(n,1,this.maxgrow);
|
|
this.length = this.lengths[this.growlvl];
|
|
this.img.path = "pill" + this.growlvl + ".png";
|
|
this.img.sync();
|
|
var d = this.img.dimensions;
|
|
this.collider.points = Geometry.box(d.x, d.y);
|
|
this.collider.sync();
|
|
|
|
this.max_x = this.extents - (d.x*this.scale)/2;
|
|
},
|
|
|
|
collide(hit) {
|
|
if (!(hit.obj.from === 'ball')) return;
|
|
var xdiff = hit.pos.x - this.pos.x;
|
|
// if (Math.sign(xdiff) === Math.sign(hit.obj.velocity)) return;
|
|
var oldvel = hit.obj.velocity;
|
|
var scaler = Math.max(Math.abs(xdiff)/30, 1.05);
|
|
hit.obj.velocity = hit.obj.velocity.scale(scaler);
|
|
},
|
|
});
|
|
|
|
gameobject.clone("upgrade_drop", {
|
|
fallspeed: 150,
|
|
tag: "ball",
|
|
upgrade: function() {},
|
|
size: 12,
|
|
phys:1,
|
|
collider: circle2d.clone(),
|
|
color: Color.Rainbow.blue,
|
|
|
|
start() {
|
|
this.collider.radius = this.size;
|
|
this.collider.sensor = true;
|
|
},
|
|
|
|
draw() {
|
|
Shape.circle(this.pos,this.size,this.color);
|
|
},
|
|
|
|
collide(hit) {
|
|
if (!(hit.obj.from === 'paddle'))
|
|
return;
|
|
|
|
this.upgrade();
|
|
this.kill();
|
|
},
|
|
|
|
update(dt) {
|
|
this.pos = this.pos.add([0,-this.fallspeed*dt]);
|
|
},
|
|
});
|