This commit is contained in:
John Alanbrook 2023-05-25 01:46:08 +00:00
parent 6f09bc72fb
commit 4a4c355fe8
4 changed files with 92 additions and 25 deletions

View file

@ -1,10 +1,29 @@
Log.warn("start of config");
gameobject.elasticity = 1;
gameobject.clone("ball", { gameobject.clone("ball", {
collider: circle2d.clone(), collider: circle2d.clone(),
img: sprite.clone(), img: sprite.clone(),
phys: 0,
elasticity: 1,
friction: 0,
collide(hit) { collide(hit) {
Sound.play("bump.wav"); 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 = { var Gameboy = {
@ -14,6 +33,8 @@ var Gameboy = {
lightest: [155,188,15] lightest: [155,188,15]
}; };
Object.freeze(Gameboy);
var Rainbow = { var Rainbow = {
red: [204,0,1], red: [204,0,1],
orange: [255,102,0], orange: [255,102,0],
@ -23,6 +44,9 @@ var Rainbow = {
blue: [53,51,255] blue: [53,51,255]
}; };
Object.freeze(Rainbow);
Object.freeze(Rainbow.yellow);
gameobject.clone("brick", { gameobject.clone("brick", {
collider: polygon2d.clone(), collider: polygon2d.clone(),
char: char2d.clone({ char: char2d.clone({
@ -47,25 +71,49 @@ gameobject.clone("brick", {
stop() { stop() {
this.timer.kill(); 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"); var act_x = Action.add_new("move");
act_x.inputs.push("axis_ljoy"); act_x.inputs.push("axis_ljoy");
var max_x = 450;
var paddle = gameobject.clone("paddle", { var paddle = gameobject.clone("paddle", {
collider: polygon2d.clone(), collider: polygon2d.clone(),
img: sprite.clone(), img: sprite.clone(),
phys: 1,
elasticity: 1,
speed: 1000, speed: 1000,
input_larrow_down() { this.input_a_down(); }, input_larrow_down() { this.input_a_down(); },
frame_vel: [0,0],
input_a_down() { 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() { 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) { gamepad_ljoy_axis(v) {
@ -78,6 +126,13 @@ var paddle = gameobject.clone("paddle", {
}, },
collide(hit) { 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");

View file

@ -2,7 +2,7 @@
"physics": { "physics": {
"gravity": [ "gravity": [
0, 0,
-50 0
], ],
"damping": 1 "damping": 1
}, },

33
game.js
View file

@ -1,7 +1,12 @@
Debug.draw_phys(true); Debug.draw_phys(true);
sim_start(); sim_start();
World.loadfile("lvl1.lvl"); 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"); //Sound.play("start.wav");
@ -26,15 +31,25 @@ var camcontroller = {
input_s_down() { cmd(102); }, input_s_down() { cmd(102); },
}; };
var score = 0;
var highscore = 0;
var lives = 3;
function texttest() function texttest() {
{ var xpos = 1000;
GUI.text("test 1", [0,0], 1,[5,120,240]);
GUI.text("test 2", [100,100],1,[100,2,250]); 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); register_gui(texttest);
Log.warn("set controller");

View file

@ -6,26 +6,22 @@
"speed": 300, "speed": 300,
"_zoom": 1, "_zoom": 1,
"speedmult": 1, "speedmult": 1,
"name": "camera2d",
"from": "gameobject" "from": "gameobject"
}, },
"polygon2d": { "polygon2d": {
"polygon2d": { "polygon2d": {
"points": [] "points": []
}, },
"name": "polygon2d",
"from": "gameobject" "from": "gameobject"
}, },
"edge2d": { "edge2d": {
"edge2d": { "edge2d": {
"cpoints": [] "cpoints": []
}, },
"name": "edge2d",
"from": "gameobject" "from": "gameobject"
}, },
"sprite": { "sprite": {
"sprite": {}, "sprite": {},
"name": "sprite",
"from": "gameobject" "from": "gameobject"
}, },
"ball": { "ball": {
@ -64,12 +60,10 @@
], ],
"_path": "pill3.png" "_path": "pill3.png"
}, },
"name": "paddle",
"from": "gameobject", "from": "gameobject",
"_scale": 2.9100000858306885 "_scale": 2.9100000858306885
}, },
"breakoutfield": { "breakoutfield": {
"name": "breakoutfield",
"from": "edge2d", "from": "edge2d",
"edge2d": { "edge2d": {
"cpoints": [ "cpoints": [
@ -80,15 +74,16 @@
], ],
"degrees": 1, "degrees": 1,
"mirrory": true, "mirrory": true,
"mirrorx": true "mirrorx": true,
"thickness": 10
} }
}, },
"brick": { "brick": {
"collider": { "collider": {
"points": [ "points": [
[ [
-37, -8,
15 4
] ]
], ],
"mirrory": true, "mirrory": true,
@ -106,13 +101,15 @@
"loop": false "loop": false
} }
}, },
"_path": "brick.png" "_path": "brick.png",
"_pos": [ -0.5, -0.5 ]
}, },
"pos": [ "pos": [
43, 43,
-165 -165
], ],
"angle": 0, "angle": 0,
"scale": 2.91,
"from": "gameobject" "from": "gameobject"
} }
} }