stupid game

Show off your games, demos and other (playable) creations.
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

stupid game

Post by zenith »

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:
stupidgameshot.png
stupidgameshot.png (9.56 KiB) Viewed 8462 times
Last edited by zenith on Fri Oct 25, 2013 10:12 am, edited 2 times in total.
ping pong
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: stupid game

Post by Jeeper »

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.
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: stupid game

Post by zenith »

done:
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
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: stupid game

Post by zenith »

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)
piediagram.png
piediagram.png (10.35 KiB) Viewed 8197 times
so, i have no idea how to make this in love. can anyone help me?
ping pong
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: stupid game

Post by micha »

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:

Code: Select all

angle = math.atan2(m.y-p.y,m.x-p.x)
Then you can insert this into the drawing function as the next parameters:

Code: Select all

love.graphics.draw(image,p.x,p.y,angle)
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

love.graphics.draw(image,p.x,p.y,angle,1,1,ox,oy)
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: stupid game

Post by zenith »

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
Last edited by zenith on Fri Oct 25, 2013 10:13 am, edited 4 times in total.
ping pong
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: stupid game

Post by micha »

zenith wrote: 1) bullets trajectory formulas, i'm completely stuck (they should fly on the player sight direction, obviously)
Once you have the angle, this is straight forward. When you fire, you assign an x- and y-velocity to each bullet according to:

Code: Select all

vx = math.cos(angle) * velocity
vy = math.sin(angle) * velocity
"velocity" is the (scalar) speed of the bullet in pixels per second.

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
for each bullet.
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: stupid game

Post by zenith »

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

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
something is wrong

thanks micha, trying to adjust the origin of bullets, works fine besides
ping pong
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: stupid game

Post by micha »

zenith wrote:something is wrong
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.


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
User avatar
zenith
Prole
Posts: 13
Joined: Sat Oct 12, 2013 5:44 pm

Re: stupid game

Post by zenith »

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!
ping pong
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests