Hi, guys! I recently started to poke love2d and i found it absolutely amazing!
I already have a bit of programming experience (i wish i had more) but still many things are obscure for me.
Here's what i made so far (about 5 hours of lurking wiki, forums and lua manual)
(based on this tutorial)
controls:
wasd - movement
zx - increase/decrease target speed
what needs to be done:
1) main menu
2) actual gameplay
3) everything else
screenshot:
stupid game
Re: stupid game
That is cool, but next time please post a .love file.
In order to make a .love file all you have to do is to zip the root of your folder and change the ending from .zip to .love. You zipped the folder itself, you have to go into that folder and zip everything inside it.
In order to make a .love file all you have to do is to zip the root of your folder and change the ending from .zip to .love. You zipped the folder itself, you have to go into that folder and zip everything inside it.
Re: stupid game
done:
game menu with QUADS
esc while in game returns to menu
game menu with QUADS
esc while in game returns to menu
Last edited by zenith on Fri Oct 25, 2013 10:12 am, edited 3 times in total.
ping pong
Re: stupid game
Do i understand this correctly?
to make player sprite rotate by following mouse cursor we need
1) get the angle a between imaginary lines AB and AC where
AB - player.x, player.y, mouse.x, mouse.y
AC - player.x, player.y, window.width, player.y
2) rotate sprite to this amount of degrees
3) return to 1)
so, i have no idea how to make this in love. can anyone help me?
to make player sprite rotate by following mouse cursor we need
1) get the angle a between imaginary lines AB and AC where
AB - player.x, player.y, mouse.x, mouse.y
AC - player.x, player.y, window.width, player.y
2) rotate sprite to this amount of degrees
3) return to 1)
so, i have no idea how to make this in love. can anyone help me?
ping pong
Re: stupid game
Let's say the player coordinates are p.x and p.y and the mouse has coordinates m.x and m.y. To get the angle you do this:
Then you can insert this into the drawing function as the next parameters:
Note that the image is rotated around the upper left corner. To make it rotate around the center point you can set the origin-coordinates within the image (ox and oy, should be half of image height and width.):
Code: Select all
angle = math.atan2(m.y-p.y,m.x-p.x)
Code: Select all
love.graphics.draw(image,p.x,p.y,angle)
Code: Select all
love.graphics.draw(image,p.x,p.y,angle,1,1,ox,oy)
Check out my blog on gamedev
Re: stupid game
stupdgame 0.0.0.1
done
minor irrelevant tweaks such as
crosshair toggle (q key)
super unrealistic laser sight
sounds
half-assed version control
clip, rounds fired counter, reloading (r key)
player rotates (thanks to micha)!
to do
help needed with theese, as always
bullets trajectory formulas, i'm completely stuck (they should fly on the player sight direction, obviously)
sounds playing in a very strange way
timer thing (player cannot fire while reloading)
mega: stupdgame 0.0.0.1.love (669 KB)
thanks to micha, trigonometry rules
done
minor irrelevant tweaks such as
crosshair toggle (q key)
super unrealistic laser sight
sounds
half-assed version control
clip, rounds fired counter, reloading (r key)
player rotates (thanks to micha)!
to do
help needed with theese, as always
bullets trajectory formulas, i'm completely stuck (they should fly on the player sight direction, obviously)
sounds playing in a very strange way
timer thing (player cannot fire while reloading)
mega: stupdgame 0.0.0.1.love (669 KB)
thanks to micha, trigonometry rules
Last edited by zenith on Fri Oct 25, 2013 10:13 am, edited 4 times in total.
ping pong
Re: stupid game
Once you have the angle, this is straight forward. When you fire, you assign an x- and y-velocity to each bullet according to:zenith wrote: 1) bullets trajectory formulas, i'm completely stuck (they should fly on the player sight direction, obviously)
Code: Select all
vx = math.cos(angle) * velocity
vy = math.sin(angle) * velocity
And then of course in the update you apply the velocity by this:
Code: Select all
bullet.x = bullet.x + bullet.vx * dt
bullet.y = bullet.y + bullet.vy * dt
Check out my blog on gamedev
Re: stupid game
side quest: this math.atan2 thing drove me mad and i tried to remember all trigonometry stuff from school (which is quite impossible) and wrote myself a problem
write a program which:
1) draws a circle
2) divide it with lines to given amount of sectors
something is wrong
thanks micha, trying to adjust the origin of bullets, works fine besides
write a program which:
1) draws a circle
2) divide it with lines to given amount of sectors
Code: Select all
origin = {}
origin.x = 150
origin.y = 150
function love.draw()
--fancy stuff
love.graphics.setPointSize(5)
love.graphics.point(150, 150)
love.graphics.line(0, 150, 300, 150)
love.graphics.line(origin.x, origin.y, mx, my)
graph(5, 80) -- divide the circle with radius 80 px 5 times
end
function graph(sections, length)
love.graphics.circle( "line", origin.x, origin.x, length)
currentAng = 0 -- starting from the begining
nextAng = 360/sections -- get the apropriate angle
currentSection = 0
while currentSection < sections do
love.graphics.line(origin.x, origin.y, origin.x + length*math.cos(currentAng), origin.y + length*math.sin(currentAng))
currentSection = currentSection + 1
currentAng = currentAng + nextAng
end
end
thanks micha, trying to adjust the origin of bullets, works fine besides
ping pong
Re: stupid game
Keep in mind that angles are stored in radiant not in degrees. The full circle has 2*pi radiant. To convert from degrees to radiant you divide by 180 and multiply by pi. And vice versa.zenith wrote:something is wrong
Besides that I'd rather make a for-loop to make those circle-segments:
Code: Select all
for i=1,nSegments do
local thisAngle = 2*math.pi*(i/nSegments)
love.graphics.line(origin.x,origin.y,origin.x+math.cos(thisAngle)*length,origin.y+math.sin(thisAngle)*length)
end
Check out my blog on gamedev
Re: stupid game
stupdgame 0.0.0.2
done:
some gui
bullets are now SHOWING
there is actually some gameplay now
sounds works normally (TEsound library)
assets are sorted to folders
bugs:
bullet start point still not defined properly
sometimes collision detection don't detect collision
to do:
add animation for target moving
add timer-based events (reloading process display, make impossible to shoot while reloading, round duration)
everything else
mega: stupdgame 0.0.0.2.love (681 KB)
thanks to micha one more time!
done:
some gui
bullets are now SHOWING
there is actually some gameplay now
sounds works normally (TEsound library)
assets are sorted to folders
bugs:
bullet start point still not defined properly
sometimes collision detection don't detect collision
to do:
add animation for target moving
add timer-based events (reloading process display, make impossible to shoot while reloading, round duration)
everything else
mega: stupdgame 0.0.0.2.love (681 KB)
thanks to micha one more time!
ping pong
Who is online
Users browsing this forum: Bing [Bot] and 2 guests