Created
April 9, 2020 02:07
-
-
Save zardilior/080467bbbd4e2705b68ba641ad282571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser-arcade-physics.min.js"></script> | |
<script> | |
// Shooter part 1 | |
/* | |
Load an image | |
insert it | |
Move our ship with arrow keys | |
Change position first | |
Use velocity next | |
*/ | |
var config = { | |
// is it canvas or webgl? (advanced) | |
type: Phaser.AUTO, | |
// the dimensions of our game | |
width: 800, | |
height: 600, | |
// Phaser divides things by scenes | |
// A scene could be a level, a room, a menu, different things, we will work with single scenes for now. To understand the basics. | |
scene: { | |
// our game functions | |
preload: preload, | |
create: create, | |
update: update | |
} | |
}; | |
var game = new Phaser.Game(config); | |
var moving = { | |
up: false, | |
down: false, | |
left: false, | |
down: false | |
} | |
// before the game loads, we load assets here like images and such | |
function preload() { | |
// load an image | |
} | |
// which helps us create the game, here we create the hero we place the different things, and we set timers. | |
function create() { | |
// insert hero ship | |
// setup an event listener | |
document.addEventListener('keydown',function(key){ | |
// check what key is pressed | |
// change the value of the related property | |
console.log(key.code); | |
}) | |
} | |
// runs every frame, each time the animation updates | |
function update(){ | |
// move our ship accordingly | |
} | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment