The index.js
JavaScript file contains the entire skeleton code which is based upon the original skeleton code provided by Diogo Eichert.
Notice: API links marked with
%source%
were undocumented at the time of this writing and link to the source code of the implementation on Github. The source may have changed by the time this document is read. Use the links to give a clue where to look in the source.
- Move the player to the loot position to gain a score point.
The player
game object (game.state.player
) is a ControllableSprite
with a size of 32x32
pixels, colored solid yellow
that has collisions enabled.
- Rect setWidth
%source%
- Rect.setHeight
%source%
- Sprite.setColor
- Sprite.setSolid
- Color enum
const player = new ControllableSprite()
// specify the dimensions of the sprite
.setWidth(32)
.setHeight(32)
// specify the color of the sprite
.setColor(Color.Yellow)
// specify that the sprite should be added to the collision detection system
.setSolid()
The loot
game object (game.state.loot
) is a Sprite
with a size of 16x16
pixels, colored solid green
that has collisions enabled.
- Videogame.sprite
%source%
-> Sprite - Rect setWidth
%source%
- Rect.setHeight
%source%
- Rect.setCenter
%source%
- get Rect.center
%source%
- Sprite.setColor
- Sprite.setSolid
- Color enum
- None
const loot = Videogame.sprite()
// specify the dimensions of the sprite
.setWidth(16)
.setHeight(16)
// set the starting position in the middle of the scene
.setCenter(scene.center)
// specify the color of the sprite
.setColor(Color.Green)
// specify that the sprite should be added to the collision detection system
.setSolid()
The score
game object (game.state.score
) is a TextSprite
with a size of 16x16
pixels, positioned in the top right corner of the scene.
- TextSprite
- Rect setWidth
%source%
- Rect.setHeight
%source%
- Rect.setRight
%source%
- Rect.setTop
%source%
- get Rect.right
%source%
- get Rect.top
%source%
- None
const score = new TextSprite()
// specify the dimensions of the sprite
.setWidth(16)
.setHeight(16)
// set the position to the top right corner of the scene
.setRight(scene.right)
.setTop(scene.top)
The starfield
game object (game.state.starfield
) is a Starfield
sprite that fills the scene with stars that move in parallax.
- Sprite.setSpeedX
%source%
- Sprite.setSpeedY
%source%
const starfield = new Starfield()
// specify the sprite motion vector towards the bottom left
.setSpeedX(-1)
.setSpeedY(1)
The scene
game object (game.state.scene
) is the base Scene
sprite object which serves as the parent of all other game objects.
- Videogame.scene
%source%
-> Scene - Sprite.setColor
- Color enum
- None
const scene = Videogame.scene()
// specify the color of the sprite
.setColor(Color.Navy)