-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
To build html files, install marp | ||
``` | ||
npm install -g @marp-team/marp-cli | ||
``` | ||
Then run `buildPDFslides.bat` or `buildHTMLslides.bat` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
marp: true | ||
paginate: true | ||
theme: borbtheme | ||
math: mathjax | ||
--- | ||
<!-- headingDivider: 3 --> | ||
<!-- class: invert --> | ||
|
||
# Coroutines | ||
|
||
## What are coroutines | ||
|
||
* Couroutines are a nifty Lua feature | ||
* Special functions that we can jump out of | ||
* and then later continue execution | ||
* from the same line we last stopped at | ||
* Coroutines can be used to | ||
* Loop through large structures one subset per frame | ||
* Construct cutscenes | ||
* Delay things | ||
|
||
## Example: Large loops | ||
|
||
```lua | ||
t=0 | ||
x=96 | ||
y=24 | ||
|
||
corout = coroutine.create(function() | ||
for i=1,10000 do | ||
if i%100==0 then | ||
x=i/100*8 | ||
coroutine.yield() | ||
end | ||
end | ||
end) | ||
|
||
function TIC() | ||
cls(13) | ||
if t%60==0 then | ||
coroutine.resume(corout) | ||
end | ||
spr(1+t%60//30*2,x,y,14,3,0,0,2,2) | ||
t=t+1 | ||
end | ||
``` |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
marp: true | ||
paginate: true | ||
theme: borbtheme | ||
math: mathjax | ||
--- | ||
<!-- headingDivider: 3 --> | ||
<!-- class: invert --> | ||
|
||
# Entities | ||
|
||
* Games usually consist of entities | ||
* In Godot, they are Nodes - in Unity, they are called GameObjects | ||
* In TIC-80, we need to create some sort of entity system ourselves. | ||
|
||
# Entity skeleton | ||
|
||
```lua | ||
entity={ | ||
x=0, | ||
y=0, | ||
w=8, | ||
h=8, | ||
init=function(ent) | ||
to(entities,ent) | ||
end, | ||
upd=function(ent) | ||
|
||
end, | ||
drw=function(ent) | ||
|
||
end, | ||
} | ||
``` | ||
|
||
# Main loop | ||
|
||
```lua | ||
function TIC() | ||
for i,ent in ipairs(entities)do | ||
ent:upd() | ||
end | ||
for i,ent in ipairs(entities)do | ||
ent:drw() | ||
end | ||
end | ||
``` | ||
|
||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
marp: true | ||
paginate: true | ||
theme: borbtheme | ||
math: mathjax | ||
--- | ||
<!-- headingDivider: 3 --> | ||
<!-- class: invert --> | ||
|
||
# Camera | ||
|
||
* TIC-80 doesn't have a built-in camera system, so you have to implement it yourself | ||
* Here's my way of doing it | ||
* Create a camera table: | ||
```lua | ||
cam={ | ||
x=0, | ||
y=0, | ||
} | ||
``` | ||
* `cam.x` and `cam.y` tell the position of the upper left corner of the camera | ||
|
||
## Drawing entities | ||
|
||
* For every entity you want to draw with respect to the camera position... | ||
* When drawing the entity on screen, subtract camera coordinates from the entity position like this: | ||
```lua | ||
spr(player.id, player.x-cam.x, player.y-cam.y) | ||
``` | ||
|
||
## Drawing the map | ||
|
||
* Drawing the map with respect to camera coordinates is a bit tricky in TIC-80 | ||
* unlike, say, `spr()`, the `map()` function does not take in the exact coordinates where we want to draw the map | ||
* Let's focus on the first six parameters of `map(x,y,w,h,sx,sh)`: | ||
* `x` and `y` are not at all the same as the `x` and `y` parameters for `spr(id,x,y)`! | ||
* They're the top-left-most cell of the map we want to draw. | ||
* (We only want to draw a small portion of the map at once!) | ||
* `w` and `h` (width and height, in cells) tell how many cells of the map we want to draw on screen. | ||
* `sx` and `sy` are the same as `x` and `y` parameters for `spr()`: | ||
* The screen coordinates where we want to draw the map. | ||
|
||
### Drawing the map with respect to the camera | ||
|
||
* We can account for the camera position if we draw the map on screen like this: | ||
```lua | ||
map(cam.x//8, cam.y//8, 31,18, -(cam.x%8), -(cam.y%8)) | ||
``` | ||
|
||
## Moving the camera | ||
|
||
* We can add an update method for the `cam` entity and update it in the main loop. | ||
* For instance, if we want the camera to center on the player: | ||
|
||
```lua | ||
cam={ | ||
x=0, | ||
y=0, | ||
w=240, | ||
h=136 | ||
upd=function(cam) | ||
cam.x,cam.y= | ||
player.x+player.w/2-cam.w/2, | ||
player.y+player.h/2-cam.h/2 | ||
end, | ||
} | ||
``` | ||
|
||
### Calling `cam.upd()` | ||
|
||
* I usually don't add special entities like camera to the `entities` table, and instead call their methods directly: | ||
|
||
```lua | ||
function TIC() | ||
for i,ent in ipairs(entities)do | ||
ent:upd() | ||
end | ||
cam:upd() | ||
for i,ent in ipairs(entities)do | ||
ent:drw() | ||
end | ||
end | ||
``` |