Jump to content

LUA tutorial na pohyb


R4lph
 Share

Recommended Posts

Začal jsem se učit LUA a tady je můj tutoš na pohyb:

--Simple moving
--by R4lph

--barvy,obrazky,promenne
white = Color.new(255,255,255)
--nacteme obrazek hrace
hrac = Image.load("player.png")
--urcime startovni pozici hrace
hrac_x = "10"
hrac_y = "10"
--hlavni cast

while true do

screen:clear()
--vykreslime obrazek hrace na startovni pozici
screen:blit(hrac_x,hrac_y,hrac)
screen:print(155,10,"Jednoduchy pohyb",white)
screen:print(160,25,"by R4lph",white)


--ovladani



pad = Controls.read()

--budeme odecitat nebo pricitat pixely tak, aby se obrazek pohyboval v danem smeru
if pad:left() then
 hrac_x = hrac_x-3
 end

if pad:right() then
 hrac_x = hrac_x+3
 end

if pad:up() then
 hrac_y = hrac_y-3
 end

if pad:down() then
 hrac_y = hrac_y+3
 end

-- zmackneme-li start, ukoncime aplikaci
if pad:start() then
break
end

--ukoncime aplikaci

screen.waitVblankStart()
screen.flip()
end

v příloze je složka luaplayerwindows.tu otevřete a spusťte run.cmd

Link to comment
Share on other sites

int main()

{kasli na to, lua je pomala chod do c a kukni do sekcie tutorialov takto sa

tutorial nepise !!!,nechcem mat patent na rozum ale necudujem sa ze tomu

nechapu, ja to precitam ale tomu co nema o programovani ani paru musis

vysvetlit aj to kde zacina loop a kde konci a do kedy bezi :D chapes?;

}

EDIT:Napriklad si im zabudol napisat ze si musia nahrat nejaky ten obrazok.png do adresara s eboot.pbp:roll:

Link to comment
Share on other sites

  • 11 months later...

a jak to teda dám tu hru do psp :psp: ?,a teda ta chyba:

-- Ukazka Menu
-- PaCMAN

-- barvy
nevm = Color.new(741,321,654)
nevim = Color.new(928,721,674)
biela = Color.new(248,259,155)
selector = Color.new(0,128,255)
zelena = Color.new(10,137,143)

-- definujem premennu
selY = 44
screen:clear()

-- vytvorim tzv. "selector" (vid. obrazok)
Image:fillRect(4, selY, 120, 10, selector)

-- nejake texty + polozky v menu
screen:print(140,5, "pacMAN", biela)
screen:print(140,12, "--------------------------", zelena)

screen:print(5,45, "Nova hra", nevm)
screen:print(5,55, "Pokracuj", biela)
screen:print(5,65, "Ovladani", biela)
screen:print(5,75, "Titulky", biela)
screen:print(5,85, "Konec", biela)
screen:print(5,115, "---------------------------------------", biela)
screen:print(5,135, "Pouzij sipky", biela)
screen:print(5,145, "Pouzi (X) pre potvrdenie", biela)

pad = Controls.read()

-- pohyb selectora za pomoci premmennej selY
if pad:down() and oldpad:down() ~= pad:down() then
selY = selY + 10
end

if pad:up() and oldpad:up() ~= pad:up() then
selY = selY - 10
end

-- toto zaisti, ze selector bude kruzit v cykle, ak ste na 5. polozke a
-- stlacite dole, selector bude na 1. polozke a naopak
if selY == 94 then
selY = 44
end

if selY == 34 then
selY = 84
end

if selY == 44 and pad:cross() and oldpad:cross() ~= pad:cross() then
screen:print(5,250, "zatim nic", nevim)
end

if selY == 54 and pad:cross() and oldpad:cross() ~= pad:cross() then
-- vykona 2. funckiu
end

if selY == 64 then
screen:print(5,250, "W je nahoru.A je do leva.D je do prava.X je dolu.", nevim)
end

if selY == 74 then
screen:print(5,250, "Vytvoreno v roce 2008", biela)
screen:print(5,260, "Autorovo jmeno:nuguien", biela)
end

if selY == 84 and pad:cross() and oldpad:cross() ~= pad:cross() then
System.Quit()
end

screen.waitVblankStart()
screen.flip()
oldpad = pad
end

vůbec nevím jak jí spravím, a nevím jaká to je ta chyba :blink::cry:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Privacy Policy