This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
My code won't start #678
Unanswered
Alvin-Alford
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am having I issues with this
import kaboom from "kaboom"
kaboom({
scale: window.innerWidth/110,
//pixelDensity: 1,
crisp : true,
background : [0,0,0],
})
//let spr = null
// load assets
loadSprite("b", "sprites/b2.png");
loadSprite("t2", "sprites/t22.png");
loadPedit("block", "sprites/block.pedit");
loadSprite("ai", "sprites/player.png");
//load(fetch("https://kaboomjs.com/"))
// onLoading((progress) => {
// // Black background
// drawRect({
// width: width(),
// height: height(),
// color: rgb(0, 0, 0),
// })
// // A pie representing current load progress
// drawCircle({
// pos: center(),
// radius: 32,
// end: map(progress, 0, 1, 0, 360),
// })
// drawText({
// text: "loading" + ".".repeat(wave(1, 4, time() * 12)),
// font: "monospace",
// size: 24,
// anchor: "center",
// pos: center().add(0, 70),
// })
// })
// if (window.self == window.top) {
// } else {
// window.open('https://Kaboom-2d-shooter-test-3000.alford.repl.co/', '_blank');
// };
const MOVE_SPEED = 280
const LEVELS = [
[
"=================",
"= =",
"= =",
" =",
"= =",
"= =",
"=================",
],
]
const levelConf = {
tileWidth: 64,
tileHeight: 64,
tiles: {
"=": () => [
sprite("block"),
pos(center()),
area(),
body({ isStatic: true }),
scale(2),
anchor("center"),
"wall",
],
},
}
camScale(0.2)
const level = addLevel(LEVELS[0], levelConf)
const gun = add([
sprite("t2"),
pos(),
area(),
scale(0.2),
anchor("bot"),
])
})
let shot = true
function shoot(){
shot = true
if (shot) {
const projectile = add([
sprite("b"),
scale(0.2),
anchor("center"),
pos(player.pos.add(
Math.sin((player.angle+90) /57)-30,
-Math.cos((player.angle+90) /57)-30,
)
),
rotate(player.pos.angle(toWorld(mousePos()))-90),
area(),
"bullet",
move(player.pos.angle(toWorld(mousePos())), -480),
])
shot = false
wait(0.1, () => {
shot = true
})
}
}
onCollide("wall","bullet", (w,b) => {
destroy(b)
//debug.log("delete")
})
onMouseDown(() => {
if (shot) {
shoot()
}
});
onKeyDown("left", () => {
player.move(-MOVE_SPEED, 0)
})
onKeyDown("right", () => {
player.move(MOVE_SPEED, 0)
})
onKeyDown("up", () => {
player.move(0, -MOVE_SPEED)
})
onKeyDown("down", () => {
player.move(0, MOVE_SPEED)
})
onKeyPress("f", () => {
fullscreen(!fullscreen())
})
// onKeyPress("e", () => {
// debug.paused = true
// })
// onKeyPress("q", () => {
// debug.paused = false
// })
//debug.inspect = true
here is the project if you want to fork
https://replit.com/@alford/Kaboom-2d-shooter3000beta?v=1
Beta Was this translation helpful? Give feedback.
All reactions