Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

TIC-80

Fantasy computer for making, playing and sharing tiny games. · By Nesbox

really confused '~' need help.

A topic by jackj106 created Dec 20, 2016 Views: 1,746 Replies: 20
Viewing posts 1 to 5

hi, i am VERY confused right now. I've been trying to recreate slot cars in tic, but the checkpoint style race code I've tried will result in the car overshooting the checkpoint that tells it to go to the next spot, and stopping right below the checkpoint by one or more pixel, UNLESS the speed its traveling at is a number you would get by continuing this sequence:0.5,1,2,4,8,16. I am attempting to make it so that when you press [z] then it makes the car go faster, but if you let go, it slowly decreases. also, the locP1={...} are the locations of the checkpoints that tell it to go to the next. point is the variable that tells it which one to be going towards. if you need the tic file, just ask. if you are confused by this description, just please look at the code.

ALSO, I WOULD PREFER TO HAVE ANY HELP BE MODS OF THE CODE, BECAUSE MOST OF LUA IS CONFUSING FOR ME, AND ITS HARD TO LOOK AT EXAMPLES AND FIGURE OUT WHAT THEY ARE SAYING.


CODE:


--slot cars



--vars
--PLR1,1plrmode
plrx=0
plry=0
--gamemode, 0=jackj106 logo,
--1=home,2=1plrmode,3=2plr mode.
mode=1
--tiles & LOCALS
t=0
sa=1
local tiles={
CORNER01=176,
TOP=177,
CORNER02=178,
RIGHT=194,
CORNER03=210,
BOTTOM=209,
CORNER04=208,
LEFT=192,
TURN01=179,
TURN02=180,
TURN03=195,
TURN04=196,
FLAMES=183
}
local locP1={
x1=16+1,
y1=88+1,
x2=40+1,
y2=88+1,
x3=40+1,
y3=96+1,
x4=96+1,
y4=96+1,
x5=96+1,
y5=32+1,
x6=136+1,
y6=32+1,
x7=136+1,
y7=104+1,
x8=192+1,
y8=104+1,
x9=224+1,
y9=72+1,
x10=128+1,
y10=56+1,
x11=48+1,
y11=16+1,
x12=48+1,
y12=32+1,
x13=16+1,
y13=32+1,
x14=16+1,
y14=56+1
}
local point=1
local lap=1



ti=0
--slot car xy
sx=16
sy=40
--angle
an=1
sa=0
--speed
spd=0.5
spddiv=1
spdx=0.5
spdy=0
--home message
hm="[Z]:1Player mode/[X]:2Player mode"
--difficulty
diff=0
diffno="None selected"
--global vars



function TIC()
cls(0)



if mode==0 then cls(0)
map()
end
if mode==1 then cls(0)
map(30,1,30,16,0,0)
print(hm,24,76)
if btn(4) then hm="Select a CPU difficulty:"
end
if hm=="Select a CPU difficulty:" then print("1",24,84)
print("2",48,84)
print("3",72,84)
print("Use ^:1 , <:2 , >:3",24,92)
print("Currently set to:",24,100)
print(diffno,128,100)
if btn(0) then diff=1
diffno="1"
end
if btn(2) then diff=2
diffno="2"
end
if btn(3) then diff=3
diffno="3"
end
print("Once chosen, press[Z]",24,108)
end
if diff>0 then t=t+1
if btn(4) then mode=2 end
end
end
if mode==2 then cls(0)
map(60,0,30,16,0,0)
spr(sa,sx,sy,0,1,0)
if point>0 then t=t+1
if point==1 then t=t+1
if sy<locP1.y1 then sy=sy+spd/spddiv
sa=5
end
if sy==locP1.y1 then point=point+1 end
end
if point==2 then t=t+1
if sx<locP1.x2 then sx=sx+spd/spddiv
sa=1
end
if sx==locP1.x2 then point=point+1 end
end
if point==3 then t=t+1
if sy<locP1.y3 then sy=sy+spd/spddiv
sa=5
end
if sy==locP1.y3 then point=point+1 end
end
if point==4 then t=t+1
if sx<locP1.x4 then sx=sx+spd/spddiv
sa=1
end
if sx==locP1.x4 then point=point+1 end
end
if point==5 then t=t+1
if sy>locP1.y5 then sy=sy-spd/spddiv
sa=13
end
if sy==locP1.y5 then point=point+1 end
end
if point==6 then t=t+1
if sx<locP1.x6 then sx=sx+spd/spddiv
sa=1
end
if sx==locP1.x6 then point=point+1 end
end
if point==7 then t=t+1
if sy<locP1.y7 then sy=sy+spd/spddiv
sa=5
end
if sy==locP1.y7 then point=point+1 end
end
if point==8 then t=t+1
if sx<locP1.x8 then sx=sx+spd/spddiv
sa=1
end
if sx==locP1.x8 then point=point+1 end
end
if point==9 then t=t+1
if sx<locP1.x9 then sx=sx+spd/spddiv
sa=15
end
end
if point==9 then t=t+1
if sy>locP1.y9 then sy=sy-spd/spddiv
sa=15
end
if sy==locP1.y9 then point=point+1 end
end
if point==10 then t=t+1
if sy>locP1.y10 then sy=sy-spd/spddiv
sa=13
end
if sy==locP1.y10 then point=point+1 end
end
if point==11 then t=t+1
if sy>locP1.y11 then sy=sy-spd/spddiv
sa=11
end
if sy==locP1.y11 then point=point+1 end
end
if point==11 then t=t+1
if sx>locP1.x11 then sx=sx-spd/spddiv
end
end
if point==12 then t=t+1
if sx>locP1.x12 then sx=sx-spd/spddiv
sa=9
end
if sx==locP1.x12 then point=point+1
end
end
if point==13 then t=t+1
if sx>locP1.x13 then sx=sx-spd/spddiv
sa=7
end

if sx==locP1.x13 then point=point+1 end
end
if point==13 then t=t+1
if sy<locP1.y13 then sy=sy+spd/spddiv end
end
if point==14 then t=t+1
if sy<locP1.y14 then sy=sy+spd/spddiv
sa=5
end
if sy==locP1.y14 then point=1 end
end
if btn(4) then spd=spd+0.5 end

end


end
if spd>0.5 then spd=spd-0.25 end
end

Developer

Could you pls make a demo page with the game on itch.io and I'll try to understand the problem.

(1 edit)

will make a wip page you have access to

need your itch.io name thingy to give you access.

Developer

My username is 'nesbox'

ok, that's weird . I put in nesbox and it said no user found

Developer

Hmm, don't know then, maybe try 'Nesbox'

(1 edit)

click here:

https://itch.io/game/accept-admin/107659/233527

then you have access to the files.

Developer

I uploaded an example for you, pls check the game and code.

So, in my version car's direction depends of the map tile under the car.

Also I'm using only integer numbers instead floats to avoid number comparsion errors.

Pls try to understand and let me know.

Thanks

thank you so much!

the code is great :D

on the "JACKJ106 GAMES PRESENTS" i added w/ help of NESBOX

Developer

Nice to hear :)

(+5)

ive got to say, i prefer TIC over PICO8. ive tried and used both, and TIC is... nicer. i like the required FUNCTION TIC(), because it rounds everything up. also, i like that TIC is free, and it is easy to contact the developer to get help :)

I agree, tic is better :)

Now we just need to port some pico-8 games to tic. A brief tutorial on how to port would be nice.

it would be cool...:)

but really difficult :(

(because of code incompatibility)

You need to get the autorisation from the authors to port games from PICO-8 to TIC

And even though, it is more interresting to make new games specific to TIC rather than ports.

You should definitly use arrays and 'for'-loop, your code is really hard to read.

Use functions to cut your code into multiple simple operations.

Also use comments to explain which part of the code do what.

And beware, TIC implement a more formal LUA than PICO-8. That means that number are double precision floating point number and not 32bit fixed point like in PICO-8. It means that if you increament by a real number, let's say 0.34 every frame and you start from x=0 and you want to check when x==1:

x = 0
while «condition» do
  if x==1 then «do a thing» end
  x = x + 0.34
end
----execution:
x==0
x==0.34
x==0.68
x==1.02 --x==1 is never checked

if you want to use check points with floating point numbers, use intervals instead of discrete values:

x = 0
while «condition» do
  if 0.9<x and x<1.1 then «do a thing» end
  x = x + 0.34
end
----execution:
x==0
x==0.34
x==0.68
x==1.02 --> 0.9<1.02<1.1 --> condition is checked !

thank you for the help and constructive criticism. :)

i honestly am a newbie in LUA. and to be honest, the normal LUA documentation is confusing!

i just kinda picked up TIC tiny computer and started to work :)

Beg your pardon sir. But i did not fail to notice that you just speak of the Luna 32bit threshold limitations


My question is. What is the number value limit that i can reach in TIC in order to prevent overflow.


And if my memory does not fail me . The "other one" has a limit of -32768.00 to 32767.99 in number range.

https://en.m.wikipedia.org/wiki/Double-precision_f...

If you deal only with integers, your limit is

253=9,007,199,254,740,992

beyond that, you cannot have the direct next natural number:

if I do 253+1 I will get 9,007,199,254,740,994 .

Can i declare a luna variable as integer like in C? I thought that the script interprets all values as float


Well that was enlighting. Thanks!

Developer

https://www.lua.org/pil/2.3.html

You can't declare integer, but you can operate with variables like with integers using regular arithmetic operators: + - * % except /

Lua has special floor division operator // for such cases. The result of x = a // b is always integer value.

https://www.lua.org/manual/5.3/manual.html#3.4.1

Ok. I get it. Thanks!