Game Reset

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
GandalftheGray
Prole
Posts: 6
Joined: Mon Dec 22, 2014 12:43 am

Game Reset

Post by GandalftheGray »

Hello everyone! This is my first post ^_^ Yay. Anyway, I have been developing a game for a couple of days, just porting it from when I had written it in python to lua, but I have run into a problem. I had a reset mechanic going in the python version but when I try to do the same in Love, it doesnt read the input at all. Heres the code:

Code: Select all

function love.load()

	--Load in images
	bg = love.graphics.newImage("images/bg.png")
	eyel = love.graphics.newImage("images/eyel.png")
	eyer = love.graphics.newImage("images/eyer.png")
	bOne = love.graphics.newImage("images/b1.png")
	wnr = love.graphics.newImage("images/wnr.png")
	lsr = love.graphics.newImage("images/lsr.png")

	--set default positions

	--Lid Positions
	elx = 159
	ely = 100 --max is 209
	erx = 471
	ery = 92 --max is 205

	--Bonus Text Positions
	bonusly = 700 -- Move to 550 to show
	bonusry = 700 -- Move to 550 to show

	--Win/Lose postitions
	wnx = 900 -- Move to 50 to show for left 600 for right
	lrx = 900 -- Move to 50 to show for left 600 for right

	--starting values
	canMove = true
	canCont = true
	closeSpeed = .3
	incSpeed = 0.001
	lMoveAmt = 25
	rMoveAmt = 25
	gameOver = false

end

function love.update()

	--add incSpeed to closeSpeed every second
	if closeSpeed < 6 and closeSpeed > 0 then
		closeSpeed = closeSpeed + incSpeed
	end

	--move left lid down
	if ely <= 209 and canMove == true then
		ely = ely + closeSpeed
	end
	--move right lid down
	if ery <= 205 and canMove == true then
		ery = ery + closeSpeed
	end

	--check for win or loose
	if ely >= 209 then
		canMove = false
		canCont = false
		wnx = 50
		lrx = 600
		gameOver = true
	end
	if ery >= 205 then
		canMove = false
		canCont = false
		wnx = 600
		lrx = 50
		gameOver = true
	end
end

function love.keypressed(key)
	if key == "z" and ely <= 209  and ely >= 100 and canCont == true then
		ely = ely - lMoveAmt
	end
	if key == "m" and ery <= 205 and ery >= 92 and canCont == true then
		ery = ery - rMoveAmt
	end
	if key == "r" then
		wnx = 900
		lrx = 900
		canCont = true
		canMove = true
		bonusly = 700
		bonusry = 700
		bly = 100
		rly = 92
	end
end

function love.draw()

	love.graphics.draw(bg, 0, 0)
	love.graphics.draw(eyel, elx, ely)
	love.graphics.draw(eyer, erx, ery)
	love.graphics.draw(bOne, 100, bonusly)
	love.graphics.draw(bOne, 600, bonusry)
	love.graphics.draw(wnr, wnx, 15)
	love.graphics.draw(lsr, lrx, 15)

end
Thanks to anyone who helps! (Sorry for the long code btw, Im new to lua and I didnt feel like making seperate files for stuff haha)
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Game Reset

Post by Azhukar »

It reads input just fine. Problem is your variable naming is a mess and you have no sense of scope in your code. Read on local variables, tables and globals.

You're doing this:

Code: Select all

bly = 100
rly = 92
Which has absolutely no effect because those variables are used nowhere else.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Game Reset

Post by Lafolie »

If you're resetting then why not call love.load()? You seem to create the same initial state, why write the code twice? :)
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests