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) )
Printable View
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) )
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)
Zitat:
Zitat von eyece
Code:angle = atan2(x2-x1, y2-y1)
easy one,...Zitat:
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...
they should seriously put animlib functions in the function reference area on the lua wiki site. im getting 50 pms every day. :p
@ 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()
end
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.. :(
Zitat:
Zitat von BlackShark
what do you mean by "doesnt work"?
also, are you trying this on windows lua?
Y? is it psp luaplayer Only? in that case ill try it out on my psp!
windows lua doesnt support transparency, so even if it did work, it wouldnt look like it.Zitat:
Zitat von BlackShark
Cool, it works, any idea on how to fade out?
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
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
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
Uber cool, it works, thanks SG57 and GrimFate! very helpfull.
so i put screen.flip() before freeing the animation and after blitting it?
I believe so..
Has anyone got any AI tuts? I'm at a dead loss :(
I second this, specifically space shooter kind of AI with enemies firing..Zitat:
Zitat von Yongobongo
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 :(
Yongobongo: I gave you this 2-3 pages back
Here is the complete listing from GameDev.Zitat:
Zitat von yaustar
http://www.gamedev.net/reference/list.asp?categoryid=18
There are also tons at http://gamasutra.com
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.
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.
In function playerMovement, you set the player's position to 0, 0 every time the function is called.
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 ?
SimpleZitat:
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.
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
it depends on how to have programed your game.Zitat:
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()
whats the problem?????Zitat:
Zitat von Cheez Pirate
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.
Because its repeating it in a while true do.