158 lines
2.8 KiB
JavaScript
158 lines
2.8 KiB
JavaScript
Log.warn("start of config");
|
|
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 */
|
|
},
|
|
});
|
|
|
|
var Gameboy = {
|
|
darkest: [15,56,15],
|
|
dark: [48,98,48],
|
|
light: [139,172,15],
|
|
lightest: [155,188,15]
|
|
};
|
|
|
|
Object.freeze(Gameboy);
|
|
|
|
var 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]
|
|
};
|
|
|
|
Object.freeze(Rainbow);
|
|
Object.freeze(Rainbow.yellow);
|
|
|
|
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 = Rainbow.red;
|
|
},
|
|
|
|
flash() {
|
|
this.char.play("flash");
|
|
},
|
|
|
|
stop() {
|
|
this.timer.kill();
|
|
},
|
|
|
|
collide(hit) {
|
|
var obj = Game.object(hit.id);
|
|
// this.timer.kill();
|
|
// this.kill();
|
|
},
|
|
|
|
draw() {
|
|
var cl = Object.create(Rainbow.yellow);
|
|
// Debug.box(this.pos, [100,30], cl);
|
|
},
|
|
|
|
});
|
|
|
|
var act_x = Action.add_new("move");
|
|
act_x.inputs.push("axis_ljoy");
|
|
|
|
var max_x = 450;
|
|
|
|
var paddle = gameobject.clone("paddle", {
|
|
collider: polygon2d.clone(),
|
|
img: sprite.clone(),
|
|
phys: 1,
|
|
elasticity: 1,
|
|
|
|
speed: 1000,
|
|
|
|
length: 50,
|
|
height: 28,
|
|
lengths: [50,70,100,130,150],
|
|
size: 0,
|
|
|
|
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]);
|
|
},
|
|
|
|
draw() {
|
|
Debug.box(this.pos, [this.length, this.height], Color.white);
|
|
},
|
|
|
|
update(dt) {
|
|
this.angle = 0;
|
|
this.pos = this.pos.add(this.frame_vel.scale(this.speed*dt)).map(p => Math.clamp(p, -max_x, max_x));
|
|
this.frame_vel = [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();
|
|
},
|
|
|
|
grow() {
|
|
this.size++;
|
|
this.length = this.lengths[this.size];
|
|
},
|
|
|
|
collide(hit) {
|
|
var xdiff = hit.pos.x - this.pos.x;
|
|
var obj = Game.object(hit.id);
|
|
if (Math.sign(xdiff) === Math.sign(obj.velocity)) return;
|
|
var oldvel = obj.velocity;
|
|
var scaler = Math.max(Math.abs(xdiff)/30, 0.9);
|
|
obj.velocity = obj.velocity.mult([-1,1]).scale(scaler);
|
|
},
|
|
});
|
|
|
|
Log.warn("end of config");
|