Lua Programming Help Thread
This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Code: distance = SQUARE ROOT ( (x2 - x1)^2 + (y2 - y1)^2) ) The angle angle between to points? ...
-
01-17-2007, 06:11 PM #5101words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
The angle angle between to points? You could get the slope, plot the hypotetnues and use sine/cosine or tangent to get the angle.Code:distance = SQUARE ROOT ( (x2 - x1)^2 + (y2 - y1)^2) )

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
01-17-2007, 06:19 PM #5102QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
This is from animlib. What do I put in the whatever section? Actually all I need to know is how to blit animations.Code:name:blit(whatever)
-
01-17-2007, 06:50 PM #5103Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von eyece
Code:angle = atan2(x2-x1, y2-y1)
--------------------------------------------------------------------------------------
-
01-17-2007, 07:11 PM #5104QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
easy one,...
Zitat von Cheez Pirate
example:blit(0, 0. 100)
"name" of animation : "blit" obvious, (X, Y, "time between frames")
the time between frames is how fast the animation is (or slow) the higher the number the longer the pause.
NOW FOR MY QUESTION
I KNOW this has came up b4, but how EXACTLY do you fade in and Out? im having troubles...
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-17-2007, 08:26 PM #5105Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
they should seriously put animlib functions in the function reference area on the lua wiki site. im getting 50 pms every day.

@ BlackShark- 1 sec, lemme write an example
-= Double Post =-
@ BlackShark:
heres a demo, havent tested it, but it should work:
Code:test = Image.load("test1.png") bg = Image.createEmpty(480, 272) speed = 1 fade = 255 while true do screen:clear() pad = Controls.read() if fade >= 0 then bg:clear(Color.new(0,0,0,fade)) screen:blit(0,0,bg) screen:blit(0,0,test) fade = fade - speed end screen.flip() screen.waitVblankStart() endGeändert von Grimfate126 (01-17-2007 um 08:26 PM Uhr) Grund: Automerged Doublepost
--------------------------------------------------------------------------------------
-
01-17-2007, 08:39 PM #5106QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
ok, thanks a bunch! going to test it now( also much thanks for animLib! animations would really suck without it...)
-= Double Post =-
Damn, does not seem to work, I tried switching the blit positions of bg and my image but that didn't work neither
what i mean by that is i took
screen:blit(0, 0, bg)
screen:blit(0, 0, contest)
and stitched them.... cuz other wise the "contest" image would blit on top of the fader, but that still didn't work..
Geändert von BlackShark (01-17-2007 um 08:39 PM Uhr) Grund: Automerged Doublepost
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-17-2007, 08:47 PM #5107Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von BlackShark
what do you mean by "doesnt work"?
also, are you trying this on windows lua?--------------------------------------------------------------------------------------
-
01-17-2007, 08:55 PM #5108QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Y? is it psp luaplayer Only? in that case ill try it out on my psp!
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-17-2007, 09:02 PM #5109Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
windows lua doesnt support transparency, so even if it did work, it wouldnt look like it.
Zitat von BlackShark
--------------------------------------------------------------------------------------
-
01-17-2007, 09:43 PM #5110QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Cool, it works, any idea on how to fade out?
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-17-2007, 09:53 PM #5111words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
I use this in all my games (in LUA so far) to fade from black to an image, then wait for abutton to press, then to fade from that image to black.
Just copy the fade in or out code to sepearte the 2. But make sure you make the alphaValue = 0 when fading out, and 255 when fading in.Code:-- get rid of any display buffer resido from game menu screen:clear() screen.waitVblankStart() screen.flip() -- Intro bg_music = Sound.load("Sound/menu.wav",true) music = bg_music:play( ) bullet = Sound.load("Sound/bullet.wav") reload = Sound.load("Sound/reload.wav") click = Sound.load("Sound/enemy_fire.wav") intro = Image.load("GFX/logo.png") fader = Image.createEmpty(480,272) alphaValue = 255 faderColor = Color.new(0,0,0,alphaValue) fader:clear(faderColor) while true do screen:clear() screen:blit(0,0,intro) screen:blit(0,0,fader) faderColor = Color.new(0,0,0,alphaValue) fader:clear(faderColor) screen.waitVblankStart() screen.flip() if alphaValue > 0 then alphaValue = alphaValue - 1 else break end end while true do blah = Controls.read() if blah:cross() or blah:circle() or blah:square() or blah:triangle() or blah:start() or blah:select() or blah:left() or blah:right() or blah:down() or blah:up() or blah:l() or blah:r() then break end end while true do screen:clear() screen:blit(0,0,intro) screen:blit(0,0,fader) if alphaValue < 255 then alphaValue = alphaValue + 1 else break end faderColor = Color.new(0,0,0,alphaValue) fader:clear(faderColor) screen.waitVblankStart() screen.flip() end
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
01-17-2007, 10:13 PM #5112QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
It won't load the begining animation. It seems like it just skips it. Then it goes directly to the load menu and in less than half a second it disapears and says I have an error on lib/animlib.lua:130: and the loading menu doesn't use animlib. But the logo does. (the very first thing that shows up. The animation.)Code:white = Color.new(255,255,255) red = Color.new(255,0,0) black = Color.new(0,0,0) dofile("lib/animlib.lua") logo = ANIM.new(8,"logo","png","logo/") loadingscreen = Image.load("images/loadingscreen.png") loadingbar = {} loadingbar.y = 12 data = {} data.loaded = 0 cursor = Image.load("images/cursor.png") data.loaded = data.loaded + 25 * 4 nameofimage = nil while true do pad = Controls.read() screen:clear(white) logo:advancedBlit(0,0,500,1) logo:free() screen:clear(white) screen:blit(0,0,loadingscreen) screen:fillRect(47,205,data.loaded,loadingbar.y,red) screen.waitVblankStart() screen.flip() end
-
01-17-2007, 10:24 PM #5113words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Want to know why?
SEe the problem?Code:while true do -- START of loop pad = Controls.read() screen:clear(white) logo:advancedBlit(0,0,500,1) -- draw animation logo:free() -- free animation before even flipping the screen screen:clear(white) screen:blit(0,0,loadingscreen) screen:fillRect(47,205,data.loaded,loadingbar.y,red) screen.waitVblankStart() screen.flip() end -- end of loop - go back to START of loop

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
01-17-2007, 10:27 PM #5114QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Uber cool, it works, thanks SG57 and GrimFate! very helpfull.
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-17-2007, 10:40 PM #5115QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
so i put screen.flip() before freeing the animation and after blitting it?
-
01-17-2007, 11:34 PM #5116QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
I believe so..
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-17-2007, 11:50 PM #5117.info

- Registriert seit
- Jun 2006
- Ort
- ACT, Australia
- Beiträge
- 1.674
- Points
- 15.395
- Level
- 80
- Downloads
- 0
- Uploads
- 0
Has anyone got any AI tuts? I'm at a dead loss
-
01-18-2007, 01:13 AM #5118QJ Gamer Silver

- Registriert seit
- Oct 2006
- Ort
- Pimp'en in the US F#
- Beiträge
- 1.254
- Points
- 7.278
- Level
- 56
- Downloads
- 0
- Uploads
- 0
I second this, specifically space shooter kind of AI with enemies firing..
Zitat von Yongobongo
NEWMy New BLOG!NEWThe Wentire Worls in two Sectors....When did I get dev statz?
Spoiler for my PSP homebrewReleases:Spoiler for Great Quotes:
-
01-18-2007, 02:02 AM #5119.info

- Registriert seit
- Jun 2006
- Ort
- ACT, Australia
- Beiträge
- 1.674
- Points
- 15.395
- Level
- 80
- Downloads
- 0
- Uploads
- 0
Check your PM blackshark, the chart by Vaza is a good resource ;)
Anyone who knows of AI tuts/snippets, i would still really like to see them as my code is very basic, and kind of crappy
-
01-18-2007, 04:11 AM #5120QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Yongobongo: I gave you this 2-3 pages back
Here is the complete listing from GameDev.
Zitat von yaustar
http://www.gamedev.net/reference/list.asp?categoryid=18
There are also tons at http://gamasutra.com[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-18-2007, 05:24 AM #5121
Here this is my code:
but as you can see its printing a moving text...But when i press a every direction ones I end up with 5 "@" and it won't go further like EG:Code:blue = Color.new(0, 0, 255) function playerMovement() Player = {X = 0, Y = 0, Health = 18} if pad:left() then Player.X = Player.X - 8 elseif pad:right() then Player.X = Player.X + 8 elseif pad:up() then Player.Y = Player.Y - 8 elseif pad:down() then Player.Y = Player.Y + 8 end end while true do pad = Controls.read() playerMovement() screen:print(Player.X,Player.Y,"@",blue) screen.waitVblankStart() screen.flip() end
->@
@@@ and when i press further more then once nothing happends.
->@
SO I want to know how do I erase other "@" as I press and How to make I go Further then only once.Free Prizes at Prizerebel Join us!
I already got 11 Gifts. Ask me for details or proof.
-
01-18-2007, 06:04 AM #5122QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
After while true do put screen:clear(). And to keep him onscreen, you can do one of two things. Edit hiks movement or put boundaries.
-
01-18-2007, 06:34 AM #5123QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
In function playerMovement, you set the player's position to 0, 0 every time the function is called.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
01-18-2007, 10:07 AM #5124Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Hi my game is near release *fingers crossed* but i have one problem. When he goes over the cheese and score goes up 1 i want the cheese to go to another random position. Anybody got tips on how to do this ?
-
01-18-2007, 12:51 PM #5125Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Simple
Zitat von eldiablov
If player over the cheese then
cheese.x = math.random and cheese.y = math.random
end
Basically when he hits that cheese and you get the score then you redeclare the cheese's coordinates to... whatever you want in your case a random number.If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
01-18-2007, 02:07 PM #5126QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
Everything loads. But at the same time. I know it's because of the 2 screen.flip()'s but I can't fix it. I put "end" behind the first screen.flip() and that doesn't work either.Code:white = Color.new(255,255,255) red = Color.new(255,0,0) black = Color.new(0,0,0) dofile("lib/animlib.lua") logo = ANIM.new(8,"logo","png","logo/") loadingscreen = Image.load("images/loadingscreen.png") loadingbar = {} loadingbar.y = 11 data = {} data.loaded = 0 cursor = Image.load("images/cursor.png") data.loaded = data.loaded + 25 * 4 nameofimage = nil while true do pad = Controls.read() screen:clear(white) logo:advancedBlit(0,0,500,1) screen.flip() screen:clear(white) screen:blit(0,0,loadingscreen) screen:fillRect(47,205,data.loaded,loadingbar.y,red) screen.waitVblankStart() screen.flip() end
-
01-18-2007, 02:59 PM #5127
it depends on how to have programed your game.Has anyone got any AI tuts? I'm at a dead loss
whats the function name for getting the square root, i remember seeing it somewhere, somthing like math.squrRoot()
-
01-18-2007, 03:03 PM #5128Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
whats the problem?????
Zitat von Cheez Pirate
--------------------------------------------------------------------------------------
-
01-18-2007, 03:09 PM #5129QJ Gamer Blue
- Registriert seit
- Aug 2006
- Ort
- Missouri
- Beiträge
- 451
- Points
- 6.041
- Level
- 50
- Downloads
- 0
- Uploads
- 0
Well it will load everything without errors but it will load and blit both the loading screen and the animation at the same time. And the screen will flash while doing so.
-
01-18-2007, 03:32 PM #5130QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Because its repeating it in a while true do.


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum