diff --git a/git/0-git-setup-slides.html b/git/0-git-setup-slides.html index 3d014ed..7d32d39 100644 --- a/git/0-git-setup-slides.html +++ b/git/0-git-setup-slides.html @@ -1,4 +1,4 @@ -
git push
)git init
git init
.git
folder.git
folder inside a directory
@@ -77,14 +77,14 @@ .git
foldergit status
git status
shows your current situation.git status
git add
git add
git add file
you tell Git that you want to do something with file
.git add .
to stage all the files in your current folder and its subfolders
@@ -112,7 +112,7 @@ git add
git add
is git rm
, which removes previously added files from Git's perspectivegit commit
git commit
git push
git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
@@ -155,7 +155,7 @@ git push
- Generally, when Git gives you a warning, error, or some other message, it's a good idea to read it and follow the orders.
git remote
git init
, don't use git clone
!
@@ -173,7 +173,7 @@ git remote
GitTest.md
is there!git pull
git pull
applies changes from the remote repository into the local repository
@@ -202,7 +202,7 @@ git pull
git clone
git clone
.gitignore
.gitignore
What happens if you make changes to the same line simultaneously?
.gitignore
.gitignore
template to keep the repository nice and clean
@@ -320,7 +320,7 @@ .gitignore
git push --set-upstream origin main
error: failed to push some refs to [your-url]
@@ -366,7 +366,7 @@ git branch -m main
to rename your local master
to main
push
and pull
commandspush
and pull
commands?
@@ -379,7 +379,7 @@ push
git status
tells you firsthand which branch you are on: On branch master
git branch
& git checkout
git branch <branchName>
@@ -53,7 +53,7 @@ git branch
& git checko
git branch <branchName>
only creates a local branchgit checkout -b <branchName>
@@ -91,7 +91,7 @@ git merge
git merge
master
branch:master
branch: no direct merging!master
.
@@ -145,7 +145,7 @@ Continue the exercise from Git Basics or create a new repository for these exercises.
@@ -174,10 +174,10 @@git merge
from command line
<<<<<<< HEAD:Player.cs
if (Input.anyKey) {
@@ -230,7 +230,7 @@ Said garbage
Use your text editor to choose which (or some combination of both) you want to preserve
git add <filename>
to add them to the commitgit log
& git checkout <hashcode>
git log
& git che
Create a new Unity project for your group.
@@ -355,7 +355,7 @@git rebase
git rebase
git rebase --abort
"fix #<issuenumber>"
or "close #<issuenumber>"
Initialize Git in the Unity project folder, pull the .gitignore
file, make your first commit and push:
git init
git commit -m "first commit"
git push --set-upstream origin main
git status
git add filename
git pull
(If working in a team, always pull before pushing!)
git push
git checkout -b newBranch
git checkout master
git merge newBranch
git commit
git push
ls
tells the contents of the working directorycd
is used to move to another directory
@@ -52,7 +52,7 @@ ..
is a shorthand for to the parent directory, .
for the current directorygit
, from any working directory, its installation folder needs to be added to System Path
@@ -73,12 +73,12 @@ Note: Windows loads the environment variables when you open a new terminal. After modifying Path, restart the terminal (if you use VS Code, you have to restart VS Code).
powershell
to run the PowerShell console in the directory.cart.lua
, not cart.tic
)require
require
package.path
package.path
<
folder
command).First, open the folder you want to use as your working directory in command line, and run the command
@@ -77,7 +77,7 @@.lua
fileThen, install Luacc in luarocks with
luarocks install luacc
luacc
. Let's continue with the previous example files, and see how they are combined back into one file:
@@ -109,12 +109,12 @@ game.lua
normally.Piano roll view:
Tracker view:
new lua
command to create a new default cartridge programmed in Luanil
valueglobal
by default (use the local
keyword!)UP=0
@@ -348,7 +348,7 @@ Boilerplate code
pi=math.pi
max=math.max
@@ -378,7 +378,7 @@ Boilerplate code
str=string.format
del=table.remove
@@ -415,7 +415,7 @@ Boilerplate code
ents = {}
table.insert(ents, {
@@ -438,7 +438,7 @@ Simple structure example
function tile(x,y)
@@ -478,7 +478,7 @@ Simple tile collision
require("file.lua")
!Download TIC-80 here. For additional help, the TIC-80 wiki start page is a good place to start from!
When you boot TIC-80 up, it opens in the command line view. Think of TIC as a tiny computer inside your computer - this is its user interface.
TIC-80 games are stored as .tic files, commonly referred to as cartridges or carts. Let's open the default cart by typing new lua
and pressing enter to execute the command. TIC-80 responds:
Now the default cart is loaded! It's not empty, and we're going to need to type another command to actually see what the cart actually contains. Let's execute the command run
, which, well, runs the loaded cart. Alternatively, you can just press CTRL+R.
There's not much: a HELLO WORLD!
text and an animated sprite which we can move with the arrow keys.
Exit the game by pressing the ESC button.
At this point it would be nice to see what made the cart act like it just did. So, we're going to take a look at the source code!
Press ESC to reveal the code editor. We can also use the shortcut button on the top left.
-- title: game title
@@ -54,7 +54,7 @@ Source code
end
The code is just 21 lines, so let's go through it step by step here.
The default cart is written in Lua, which is a programming language a bit like Python. This page is a great introduction to Lua!
@@ -65,7 +65,7 @@Then, we declare some variables and give them values. It's easy in lua:
t=0
@@ -78,11 +78,11 @@ Variables and coordinates
To see what this accomplishes, we can run the cart again.
The smiling sprite is now in the top-left corner! The top-left corner is indeed the origin, and (unlike in maths and physics) the positive values of y
go down from the origin. The bottom-right corner has the coordinates x=240, y=136
. The resolution of TIC-80 is just that, 240 by 136 pixels.
Let's continue onwards! Now we get to the most important function, the main loop of the game, TIC()
.
function TIC()
@@ -91,7 +91,7 @@ The main loop and function decla
TIC()
is called 60 times in a second. Here, we declare it: every time it's called, TIC-80 executes stuff inside. Inside it the game does its magic: we change values of some variables, draw all kinds of stuff on screen, etc.
All functions are declared the same way - starting with function functionname()
and ending with end
. For example, a sum function would be
function sum(a,b)
local sum = a + b
@@ -101,7 +101,7 @@ The main loop and function decla
We could then call it with, say, sum(5,2)
and get a satisfying result of 7
.
Unlike Python, Lua doesn't necessitate the use of indentation, but using it produces clearer code.
But what did we have inside TIC()
, again?
First, there were these four lines:
@@ -111,7 +111,7 @@A basic if statement in Lua is of the form
if something then
dostuff()
@@ -127,27 +127,27 @@ Pressing buttons and if statements
end
But let's not get ahead of ourselves! Inside those four lines, we change the values of y and x only if a certain button is down, and the function btn(i)
tests this.
Buttons are indexed with numbers in TIC-80:
0 means up, 1 means down, 2 means left and 3 means right. Which number denotes which button is documented in the key map page, and the function btn()
has its own wiki page describing how it works, like all the functions available in TIC-80 do.
After the button pressing lines we have this function call:
cls(13)
It isn't inside any if statements, so it's called 60 times per second! The function call clears the screen. In other words it paints the screen with a solid colour. The colours, like buttons before, are indexed with numbers - we have 16 colours to use. The 13 which was seen here, corresponds to a light blue colour.
We could now take a slight detour to the sprite editor by pressing F2.
The colour palette is located in the bottom left - and if we count from 0, light blue is number 13. We could fiddle with the pen tool and draw stuff (see our moving sprite on the right side!), but let's go back to code editor by pressing the button on the top-left corner, or F1.
So it's possible to change the background colour by changing the argument of the cls()
function to some other number from 0 to 15. We could also remove the function call altogether to get some interesting effects...
After cls()
we have a rather nasty-looking statement.
spr(1+t%60//30_2,x,y,14,3,0,0,2,2)
@@ -157,7 +157,7 @@ Hello world!
This is the print function; it just draws the white text HELLO WORLD
to coordinates 84, 84.
Then we have
t=t+1
@@ -165,11 +165,11 @@ Incrementing values
TIC()
gets called 60 times per second, and every time t is increased by 1. So in one second, it gets increased by 60! It tells the passage of time, and its units are frames, not seconds. It will provide itself useful later!
An important note: to be able to use the expression above, we have to have an initial value for t
, and at the beginning, we declared it to be 0
. In Python we could use a shorthand t+=1
, but on Lua this isn't unfortunately possible!
Now we have reached the end of the TIC()
function, so it's time to get back to this:
spr(1+t%60//30*2,x,y,14,3,0,0,2,2)
@@ -178,18 +178,18 @@ 1: The sprite memory
spr(1,x,y)
Now we get...
So, it still draws... something? At least the sprite is still drawn in the coordinates x
and y
, which change as we press the directional buttons.
Let's take a look at the sprite function description. It says
spr id x y [colorkey=-1] [scale=1] [flip=0] [rotate=0] [w=1 h=1]
This essentially means that the function is called like this:
spr( id, x, y, colorkey, scale, flip, rotate, w, h )
Mind that the arguments in [brackets]
are optional, having their default values written out in description. That's why we can just call the function with
spr(1, x, y)
@@ -198,12 +198,12 @@ Note: The order of arguments matters, so if you want to use the "rotate" argument, you have to include colorkey, scale and flip, too!
The id
argument tells which sprite to load from memory. You can see all the sprites saved to the sprite memory in sprite editor. It contains two sections (FG and BG, or foreground and background), each containing 256 8x8 sprites. BG contains sprites with ids 0-255 and FG 256-511. You can change between the slots by pressing TAB.
The only difference between FG and BG memory slots is this: we can use the sprites from the BG memory to draw the map in the map editor - more on that later! But for the spr(), we can call any sprite from BG or FG slots: just call the sprite with a number from 0 to 511.
But let's not get ahead of ourselves, let's go back to spr()
!
The function description tells that if we want to draw multiple sprites with just one spr() call, we adjust the width and height arguments! If we change them both to 2 and call the function as
spr(1, x, y, -1, 1, 0, 0, 2, 2)
@@ -212,7 +212,7 @@ 2: Optional arguments
spr(1, x, y, -1, 3, 0, 0, 2, 2)
Now we'd like to get rid of the yellow background. There isn't a transparent colour in TIC-80, so we have to deliberately choose which colour will be transparent with colorkey
. By default all colours are drawn (it's -1), so to make yellow transparent, we change it to
spr(1, x, y, 14, 3, 0, 0, 2, 2)
@@ -220,13 +220,13 @@ spr(3, x, y, 14, 3, 0, 0, 2, 2)
The original sprite call used a clever trick to make the value jump between 1 and 3 every half seconds (or 30 frames). We can test it by printing its value in the print() function:
print(1+t%60//30*2,84,84)
Let's break the value down:
1+t%60//30*2
@@ -234,7 +234,7 @@ For example, we have the division
And as we might remember from earlier, t
tells how many frames have passed since the beginning of the game. By using the modulo operator with number
t%60
returns values
Similarly, t%2
returns values
1+t%2*2
Numbers we get from the statement above change way too fast to make for a readable animation. To make it slower we use the floor division operator //
, which isn't part of regular Lua but is added to TIC-80. It's basically a counterpart for the modulo operator, giving the result of division operation without the remainder, or in other terms without any decimals that we would get from regular division:
So with floor division we always get integers as a result! It's indeed useful, as e.g. the sprite ids are always integers.
So.
Let's denote the first part,
jumps between
To get the desired values
1+t%60//30*2
@@ -267,5 +267,5 @@ But that was (mostly) only about the code
editor - in the next lesson we'll get acquainted with the other editors!
Now it's time to go through the general workflow of making games with TIC-80.
Note: This part of the tutorial is still work in progress.
In the previous part, we created a new default cart with the command new
. It might be a good idea to now save it! That's done with the command
save cartname.tic
@@ -25,7 +25,7 @@ Saving and loading
(Tip: You can autocomplete commands: In the previous command, you could just write load c
and press TAB and TIC will complete the command!)
But where are the carts?
They are inside the TIC's data folder, the only folder visible to TIC-80. For easy access, the folder can be revealed in Explorer with command folder
.
Move to a folder with command cd foldername
. To go back to the parent directory, use command cd ..
.
Additionally, you can use mkdir foldername
to create a new, empty folder. Similarly, del filename
can be used to delete files or folders. Be careful here, though!
If there isn't any carts to see, we see the prompt
use ADD or DEMO command to add carts
@@ -42,12 +42,12 @@ Adding demo carts
add
copies a cart from any folder to TIC's data folder.
demo
is a more interesting command: it adds nine demo carts to the data folder.
A good way to see the capabilities of any tool is to see what people have made with it. So where to start?
Well, there are many carts hosted on the TIC's website!
help
gives the list of available commands.
new lua
loads a new default cart. It contains a very barebones Hello World example.
resume
: Resume your running game.
entity={
+ x=0,
+ y=0,
+ w=8,
+ h=8,
+ init=function(ent)
+ to(entities,ent)
+ end,
+ upd=function(ent)
+
+ end,
+ drw=function(ent)
+
+ end,
+}
+
+function TIC()
+ for i,ent in ipairs(entities)do
+ ent:upd()
+ end
+ for i,ent in ipairs(entities)do
+ ent:drw()
+ end
+end
+
+cam={
+ x=0,
+ y=0,
+}
+
+cam.x
and cam.y
tell the position of the upper left corner of the cameraspr(player.id, player.x-cam.x, player.y-cam.y)
+
+spr()
, the map()
function does not take in the exact coordinates where we want to draw the mapmap(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)
!
+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()
:
+map(cam.x//8, cam.y//8, 31,18, -(cam.x%8), -(cam.y%8))
+
+cam
entity and update it in the main loop.
+For instance, if we want the camera to center on the player:
+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,
+}
+
+cam.upd()
entities
table, and instead call their methods directly: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
+
+