This commit is contained in:
John Alanbrook 2023-06-07 22:26:38 +00:00
parent 003655b06a
commit d8420594b6
3 changed files with 53 additions and 4 deletions

View file

@ -113,9 +113,9 @@ var flashtimer = timer.make(function() {
var paddle = World.spawn(gameobjects['paddle']); var paddle = World.spawn(gameobjects['paddle']);
paddle.extents = lvlwidth/2 - f.edge2d.thickness; paddle.extents = lvlwidth/2 - f.edge2d.thickness;
paddle.lasership();
paddle.pos = [0,-lvlheight/2+paddle.height*4]; paddle.pos = [0,-lvlheight/2+paddle.height*4];
paddle.setgrow(3); paddle.setgrow(3);
paddle.lasership();
Gamestate.spawnball = function() { Gamestate.spawnball = function() {
var bb = World.spawn(gameobjects['ball']); var bb = World.spawn(gameobjects['ball']);

View file

@ -8,3 +8,5 @@
- Specifically, want to monitor for screen change - Specifically, want to monitor for screen change
- Look up collision functions dynamically instead of with registry - Look up collision functions dynamically instead of with registry
-Missiles flash for one frame where previous

View file

@ -36,6 +36,10 @@ gameobject.clone("brick", {
points: 50, points: 50,
getshot() {
this.kill();
},
start() { start() {
this.char.stop(); this.char.stop();
this.flash(); this.flash();
@ -58,6 +62,34 @@ gameobject.clone("brick", {
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");
gameobject.clone("missile", {
collider: polygon2d.clone(),
phys: 1,
bwidth: 5,
bheight: 15,
speed: 200,
start() {
this.collider.points = Geometry.box(this.bwidth, this.bheight);
this.collider.sensor = true;
},
collide(hit) {
if ('getshot' in hit.obj) {
hit.obj.getshot();
this.kill();
}
},
draw() {
Debug.box(this.pos, [this.bwidth, this.bheight], Color.cyan);
},
update(dt) {
this.pos = this.pos.add([0,this.speed*dt]);
},
});
var paddle = gameobject.clone("paddle", { var paddle = gameobject.clone("paddle", {
collider: polygon2d.clone(), collider: polygon2d.clone(),
img: sprite.clone(), img: sprite.clone(),
@ -128,10 +160,20 @@ var paddle = gameobject.clone("paddle", {
lasership() { lasership() {
this.laser = true; this.laser = true;
this.img.color = Color.Gameboy.light;
},
unlasership() {
this.laser = false;
this.img.color = Color.white;
}, },
shoot() { shoot() {
Log.warn("SHOOTING MISSILES"); Log.warn("FIRING MISSILE");
var m1 = World.spawn(gameobjects['missile']);
// var m2 = World.spawn(gameobjects['missile']);
m1.pos = this.pos.add([(this.length/2)-5,0]);
// m2.pos = this.pos.add([5-(this.length/2),0]);
}, },
sticky: false, sticky: false,
@ -150,13 +192,18 @@ var paddle = gameobject.clone("paddle", {
} }
}, },
start() {
this.collider.sensor = true;
},
collide(hit) { collide(hit) {
if (!(hit.obj.from === 'ball')) return; if (!(hit.obj.from === 'ball')) return;
var xdiff = hit.pos.x - this.pos.x; var xdiff = hit.pos.x - this.pos.x;
var hitangle = xdiff/this.length - 0.5; var hitangle = (xdiff/this.length + 0.5) * Math.PI;
hitangle = Math.clamp(hitangle, Math.PI/6, 5*Math.PI/6);
var speed = Vector.length(hit.obj.velocity); var speed = Vector.length(hit.obj.velocity);
hit.obj.velocity = [Math.cos(hitangle)*speed, Math.sin(hitangle)*speed]; hit.obj.velocity = [Math.cos(hitangle)*speed, -Math.sin(hitangle)*speed];
hit.obj.velocity = hit.obj.velocity.scale(-1); hit.obj.velocity = hit.obj.velocity.scale(-1);
var oldvel = hit.obj.velocity; var oldvel = hit.obj.velocity;
var scaler = Math.max(Math.abs(xdiff)/30, 1.01); var scaler = Math.max(Math.abs(xdiff)/30, 1.01);