breakout
This commit is contained in:
parent
6f09bc72fb
commit
4a4c355fe8
61
config.js
61
config.js
|
@ -1,10 +1,29 @@
|
|||
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 = {
|
||||
|
@ -14,6 +33,8 @@ var Gameboy = {
|
|||
lightest: [155,188,15]
|
||||
};
|
||||
|
||||
Object.freeze(Gameboy);
|
||||
|
||||
var Rainbow = {
|
||||
red: [204,0,1],
|
||||
orange: [255,102,0],
|
||||
|
@ -23,6 +44,9 @@ var Rainbow = {
|
|||
blue: [53,51,255]
|
||||
};
|
||||
|
||||
Object.freeze(Rainbow);
|
||||
Object.freeze(Rainbow.yellow);
|
||||
|
||||
gameobject.clone("brick", {
|
||||
collider: polygon2d.clone(),
|
||||
char: char2d.clone({
|
||||
|
@ -47,25 +71,49 @@ gameobject.clone("brick", {
|
|||
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,
|
||||
|
||||
input_larrow_down() { this.input_a_down(); },
|
||||
|
||||
frame_vel: [0,0],
|
||||
|
||||
input_a_down() {
|
||||
this.pos = this.pos.add([-1,0].scale(this.speed*Yugine.dt));
|
||||
this.frame_vel = this.frame_vel.add([-1,0]);
|
||||
},
|
||||
|
||||
input_d_down() {
|
||||
this.pos = this.pos.add([1,0].scale(this.speed*Yugine.dt));
|
||||
this.frame_vel = this.frame_vel.add([1,0]);
|
||||
},
|
||||
|
||||
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) {
|
||||
|
@ -78,6 +126,13 @@ var paddle = gameobject.clone("paddle", {
|
|||
},
|
||||
|
||||
collide(hit) {
|
||||
Log.warn("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");
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"physics": {
|
||||
"gravity": [
|
||||
0,
|
||||
-50
|
||||
0
|
||||
],
|
||||
"damping": 1
|
||||
},
|
||||
|
@ -131,4 +131,4 @@
|
|||
},
|
||||
"num": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
33
game.js
33
game.js
|
@ -1,7 +1,12 @@
|
|||
Debug.draw_phys(true);
|
||||
sim_start();
|
||||
World.loadfile("lvl1.lvl");
|
||||
World.spawn(gameobjects['ball']);
|
||||
var b = World.spawn(gameobjects['ball']);
|
||||
b.collider.sensor = true;
|
||||
b.draw_layer = 4;
|
||||
var bb = World.spawn(gameobjects['ball']);
|
||||
bb.pos = bb.pos.add([50,0]);
|
||||
bb.draw_layer = 3;
|
||||
|
||||
//Sound.play("start.wav");
|
||||
|
||||
|
@ -26,15 +31,25 @@ var camcontroller = {
|
|||
input_s_down() { cmd(102); },
|
||||
};
|
||||
|
||||
var score = 0;
|
||||
var highscore = 0;
|
||||
var lives = 3;
|
||||
|
||||
function texttest()
|
||||
{
|
||||
GUI.text("test 1", [0,0], 1,[5,120,240]);
|
||||
GUI.text("test 2", [100,100],1,[100,2,250]);
|
||||
function texttest() {
|
||||
var xpos = 1000;
|
||||
|
||||
GUI.text("SCORE", [xpos,500],1,Color.red);
|
||||
GUI.text(`${score}`, [xpos,480],1);
|
||||
|
||||
GUI.text("HIGH SCORE", [xpos,450],1, Color.red);
|
||||
GUI.text(`${highscore}`, [xpos,430],1);
|
||||
|
||||
GUI.text(`LIVES: ${lives}`, [xpos, 400], 1, Color.white);
|
||||
|
||||
GUI.text("YARKANOID", [xpos,300], 1,[5,120,240]);
|
||||
|
||||
GUI.text("ODPLOT GAMES", [xpos,250],1);
|
||||
GUI.text("[C] 2023", [xpos,230]);
|
||||
}
|
||||
|
||||
register_gui(texttest);
|
||||
|
||||
|
||||
Log.warn("set controller");
|
||||
|
||||
|
|
19
proto.json
19
proto.json
|
@ -6,26 +6,22 @@
|
|||
"speed": 300,
|
||||
"_zoom": 1,
|
||||
"speedmult": 1,
|
||||
"name": "camera2d",
|
||||
"from": "gameobject"
|
||||
},
|
||||
"polygon2d": {
|
||||
"polygon2d": {
|
||||
"points": []
|
||||
},
|
||||
"name": "polygon2d",
|
||||
"from": "gameobject"
|
||||
},
|
||||
"edge2d": {
|
||||
"edge2d": {
|
||||
"cpoints": []
|
||||
},
|
||||
"name": "edge2d",
|
||||
"from": "gameobject"
|
||||
},
|
||||
"sprite": {
|
||||
"sprite": {},
|
||||
"name": "sprite",
|
||||
"from": "gameobject"
|
||||
},
|
||||
"ball": {
|
||||
|
@ -64,12 +60,10 @@
|
|||
],
|
||||
"_path": "pill3.png"
|
||||
},
|
||||
"name": "paddle",
|
||||
"from": "gameobject",
|
||||
"_scale": 2.9100000858306885
|
||||
},
|
||||
"breakoutfield": {
|
||||
"name": "breakoutfield",
|
||||
"from": "edge2d",
|
||||
"edge2d": {
|
||||
"cpoints": [
|
||||
|
@ -80,15 +74,16 @@
|
|||
],
|
||||
"degrees": 1,
|
||||
"mirrory": true,
|
||||
"mirrorx": true
|
||||
"mirrorx": true,
|
||||
"thickness": 10
|
||||
}
|
||||
},
|
||||
"brick": {
|
||||
"collider": {
|
||||
"points": [
|
||||
[
|
||||
-37,
|
||||
15
|
||||
-8,
|
||||
4
|
||||
]
|
||||
],
|
||||
"mirrory": true,
|
||||
|
@ -106,13 +101,15 @@
|
|||
"loop": false
|
||||
}
|
||||
},
|
||||
"_path": "brick.png"
|
||||
"_path": "brick.png",
|
||||
"_pos": [ -0.5, -0.5 ]
|
||||
},
|
||||
"pos": [
|
||||
43,
|
||||
-165
|
||||
],
|
||||
"angle": 0,
|
||||
"scale": 2.91,
|
||||
"from": "gameobject"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue