Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/borbware/tic80-basics
Browse files Browse the repository at this point in the history
  • Loading branch information
borbware committed Nov 26, 2024
2 parents 9c04a3a + 27aa8a5 commit 335a258
Show file tree
Hide file tree
Showing 19 changed files with 602 additions and 246 deletions.
32 changes: 16 additions & 16 deletions git/0-git-setup-slides.html

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions git/1-git-basics-slides.html

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions git/2-git-continued-slides.html

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions git/3-github-tools-slides.html

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions git/git-cheat-sheet-slides.html

Large diffs are not rendered by default.

46 changes: 25 additions & 21 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,48 @@ If you have any suggestions, hit me up - I'm `@borbware` on Discord.
* [TIC-80 Manual & Cheat Sheet webpage](https://skyelynwaddell.github.io/tic80-manual-cheatsheet/) by skye & parlortricks
* [TIC-80 Cheat sheet pdf](https://zenithsal.com/assets/documents/tic-80_cheatsheet.pdf)
* [TIC-80 sizecoding](http://www.sizecoding.org/wiki/TIC-80)
* [Awesome TIC-80](https://github.com/stefandevai/awesome-tic-80): A curated list of tutorials, resources and links



## Example repositories

* [TIC-80 boilerplate](https://github.com/borbware/tic80-boilerplate): A multi-file project example
* [TIC-80 demo workshop by creativenucleus](https://github.com/creativenucleus/tic-80-demo-workshop/tree/main): Coding graphical effects
* More to come!


## TIC-80 Basics

| | | Slides | Page | |
| --- | ---------------- | --------------------------------------------- | --------------------------------- | ---: |
| 0 | What is TIC-80? | [🎞](tic80-basics/0-what-is-tic80-slides.html) | [📖](tic80-basics/0-what-is-tic80) | 🌕 |
| 1 | The default cart | [🎞](tic80-basics/1-default-cart-slides.html) | [📖](tic80-basics/1-default-cart) | 🌕 |
| 2 | Workflow | [🎞](tic80-basics/2-workflow-slides.html) | [📖](tic80-basics/2-workflow) | 🌒 |
| 3 | API | [🎞](tic80-basics/3-API-slides.html) | [📖](tic80-basics/3-API) | 🌒 |
| | | Slides | Page | |
|---|------------------|------------------------------------------------|------------------------------------|---:|
| 0 | What is TIC-80? | [🎞](tic80-basics/0-what-is-tic80-slides.html) | [📖](tic80-basics/0-what-is-tic80) | 🌕 |
| 1 | The default cart | [🎞](tic80-basics/1-default-cart-slides.html) | [📖](tic80-basics/1-default-cart) | 🌕 |
| 2 | Workflow | [🎞](tic80-basics/2-workflow-slides.html) | [📖](tic80-basics/2-workflow) | 🌒 |
| 3 | API | [🎞](tic80-basics/3-API-slides.html) | [📖](tic80-basics/3-API) | 🌒 |
| 4 | Entities | [🎞](tic80-basics/4-entities-slides.html) | [📖](tic80-basics/4-entities) | 🌒 |
| 5 | Camera | [🎞](tic80-basics/5-camera-slides.html) | [📖](tic80-basics/5-camera) | 🌒 |

## TIC-80 Advanced

| | | Slides | Page | |
| --- | ------------------- | --------------------------------------------------- | --------------------------------------- | ---: |
| | Building TIC-80 | [🎞](tic80-advanced/building-tic80-slides.html) | [📖](tic80-advanced/building-tic80) | 🌒 |
| | Multi-file projects | [🎞](tic80-advanced/multi-file-projects-slides.html) | [📖](tic80-advanced/multi-file-projects) | 🌒 |
| | | Slides | Page | |
|--|---------------------|------------------------------------------------------|------------------------------------------|---:|
| | Building TIC-80 | [🎞](tic80-advanced/building-tic80-slides.html) | [📖](tic80-advanced/building-tic80) | 🌒 |
| | Multi-file projects | [🎞](tic80-advanced/multi-file-projects-slides.html) | [📖](tic80-advanced/multi-file-projects) | 🌒 |

## Project management

| | | Slides | Page | |
| --- | --------------------- | --------------------------------------------------------- | --------------------------------------------- | ---: |
| | Command line and PATH | [🎞](project-management/command-line-and-path-slides.html) | [📖](project-management/command-line-and-path) | 🌓 |
| | Windows file explorer | [🎞](project-management/windows-file-explorer-slides.html) | [📖](project-management/windows-file-explorer) | 🌓 |
| | | Slides | Page | |
|--|-----------------------|------------------------------------------------------------|------------------------------------------------|---:|
| | Command line and PATH | [🎞](project-management/command-line-and-path-slides.html) | [📖](project-management/command-line-and-path) | 🌓 |
| | Windows file explorer | [🎞](project-management/windows-file-explorer-slides.html) | [📖](project-management/windows-file-explorer) | 🌓 |

## Using Git

| | | Slides | Page | |
| --- | --------------- | ------------------------------------ | ------------------------ | ---: |
| 0 | Git setup | [🎞](git/0-git-setup-slides.html) | [📖](git/0-git-setup) | 🌕 |
| 1 | Git basics | [🎞](git/1-git-basics-slides.html) | [📖](git/1-git-basics) | 🌕 |
| 2 | Git continued | [🎞](git/2-git-continued-slides.html) | [📖](git/2-git-continued) | 🌕 |
| 3 | GitHub tools | [🎞](git/3-github-tools-slides.html) | [📖](git/3-github-tools) | 🌔 |
| | Git cheat sheet | [🎞](git/git-cheat-sheet-slides.html) | [📖](git/git-cheat-sheet) | 🌕 |
| | | Slides | Page | |
|---|-----------------|---------------------------------------|---------------------------|---:|
| 0 | Git setup | [🎞](git/0-git-setup-slides.html) | [📖](git/0-git-setup) | 🌕 |
| 1 | Git basics | [🎞](git/1-git-basics-slides.html) | [📖](git/1-git-basics) | 🌕 |
| 2 | Git continued | [🎞](git/2-git-continued-slides.html) | [📖](git/2-git-continued) | 🌕 |
| 3 | GitHub tools | [🎞](git/3-github-tools-slides.html) | [📖](git/3-github-tools) | 🌔 |
| | Git cheat sheet | [🎞](git/git-cheat-sheet-slides.html) | [📖](git/git-cheat-sheet) | 🌕 |
20 changes: 10 additions & 10 deletions project-management/command-line-and-path-slides.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions project-management/windows-file-explorer-slides.html

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions setup.md
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`
47 changes: 47 additions & 0 deletions tic80-advanced/coroutines.md
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
```
26 changes: 13 additions & 13 deletions tic80-advanced/multi-file-projects-slides.html

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions tic80-basics/0-what-is-tic80-slides.html

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions tic80-basics/1-default-cart-slides.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions tic80-basics/2-workflow-slides.html

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions tic80-basics/3-API-slides.html

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions tic80-basics/4-entities-slides.html

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions tic80-basics/4-entities.md
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
```


111 changes: 111 additions & 0 deletions tic80-basics/5-camera-slides.html

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions tic80-basics/5-camera.md
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
```

0 comments on commit 335a258

Please sign in to comment.