https://www.sqa.org.uk/files/nu/FN8R11.pdf
Upon Completion of this Unit you will be able to
Design a game concept
Produce a Working Demo
Evaluate Demo
Commenting
Indentation
Naming
Variables
Data Structures
Control Structures
Operators
https://www.lexaloffle.com/pico-8.php
Pico-8 is an IDE ( Integrated Developer Environment ) that uses the Lua programming language.
Pico-8 attempts to replicate the limitations of 8bit video games systems.
Sticking to these limitations helps us to control the scope of our projects and means we only have to worry about one program when we are starting out.
Text Commands
Code Editor
Sprite Editor
Tile Editor
Sound Effects
Music Tracker
init
draw
update
We press Escape to enter the blank code screen
In order to clear the screen we type;
CLS()
If we run this code we can see that the screen is cleared
PRINT("HELLO")
This will print the word hello on the screen.
SPR(0,64,64)
In this example 0 selects sprite slot 0, 64 draw the sprite 64 pixels along horizontally, and, the next 64 draws the sprite 64 pixels along vertically
SPR(0,x,64)
X=64
X=X+1
FUNCTION _INIT()
This function contains and initializes all the variables that we will use.
FUNCTION _DRAW()
This function describes all the elements that will be drawn on the screen.
FUNCTION _UPDATE()
This function contains all of the game logic. This function is called 30 times each second.
FUNCTION _INIT()
x=64
END
FUNCTION _DRAW()
SPR(0,x,64)
END
FUNCTION _UPDATE()
X=X+1
END
This example will sho our sprite moving to the right forever.
FUNCTION _UPDATE()
IF BTN(1) THEN
X=X+1
END
END
Now our sprite will only move when we press the right arrow key.
FUNCTION _UPDATE()
IF BTN(1)
THEN X=X+1
END
IF BTN(0)
THEN X=X-1
END
END
Now our sprite can move both to the left and to the right.
FUNCTION _UPDATE()
IF BTN(1) THEN
X=X+1
END
IF BTN(0)THEN
X=X-1
END
IF X>120 THEN
X=120
END
END
We can use this to limit the movement in the other direction as well.
FUNCTION _UPDATE()
IF BTN(1) THEN
X=X+1
END
IF BTN(0)THEN
X=X-1
END
IF X>120 THEN
X=120
END
IF X<0 THEN
X=0
END
END
You should always avoid using sprite slot 0.
FUNCTION _INIT()
X=64
S=1
END
FUNCTION _DRAW()
CLS()
SPR(S,X,64)
END
FUNCTION _UPDATE()
IF BTN(1) THEN
X=X+1
END
IF BTN(0)THEN
X=X-1
S=S+1
END
IF X>120 THEN
X=120
END
IF X<0 THEN
X=0
END
IF S>2 THEN
S=1
END
END
SPR(S,X,64,1,1,TRUE)
In order to manipulate this value ‘TRUE’, we need to give it a name and then initialize it in our init function.
SPR(S,X,64,1,1,F)
F=FALSE
FUNCTION _INIT()
X=64
S=1
F=FALSE
END
FUNCTION _DRAW()
CLS()
SPR(S,X,64)
END
FUNCTION _UPDATE()
IF BTN(1) THEN
X=X+1
S=S+1
F=FALSE
END
IF BTN(0)THEN
X=X-1
S=S+1
F=TRUE
END
IF X>120 THEN
X=120
END
IF X<0 THEN
X=0
END
IF S>2 THEN
S=1
END
END
Now our sprite will flip direction depending on which way it is travelling.
FUNCTION _INIT()
X=64--HORIZONTAL SPRITE VALUE
S=1--SPRITE SLOT
F=FALSE--FLIP SPRITE HORIZONTALLY
END
FUNCTION _DRAW()
CLS()--CLEAR SCREEN
SPR(S,X,64)--DRAW SPRITE
END
FUNCTION _UPDATE()
IF BTN(1) THEN--RIGHT KEY
X=X+1--MOVE SPRITE RIGHT
S=S+1--ANIMATE
F=FALSE
END
IF BTN(0)THEN--LEFT KEY
X=X-1--MOVE SPRITE LEFT
S=S+1--ANIMATE
F=TRUE--FLIP SPRITE
END
IF X>120 THEN--LIMIT X AT RIGHT EDGE OF SCREEN
X=120
END
IF X<0 THEN--LIMIT X AT LEFT EDGE OF SCREEN
X=0
END
IF S>2 THEN--LOOP ANIMATION
S=1
END
END