PlatformGuy! V0.4

Show off your games, demos and other (playable) creations.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: PlatformGuy! V0.2

Post by Robin »

WolfNinja2 wrote:right now I want to understand fundementals and all that jazz, not focus on pretty coding :/
It's not about being pretty, it's about maintainability.
WolfNinja2 wrote:You're right, I do want to expand a LOT, but I don't think he's talking about indentation really. I think he means how my coding works. BUT, if he's talking about the indentation I can do that no problem! In fact, I'm going to do it either way now that you mention it xD
Indentation is a part of it. Other parts you might want to consider are:
  • Variable naming. Ask yourself: will you know what this name means when you get back to it a month from now? A year?
  • Comments. Comments should tell you "why", not "how": they tell you what a certain function is for, why you did things the way you did them, things like that.
  • Structure. What belongs in what file, and in which table you put which function is not an exact science, but you have to think about it otherwise you'll never find anything in your code. ("Where do I actually draw the player?")
All these problems are reasonably manageable, but as your game grows, so do the problems. It's like cleaning your room: my parents always told me to clean it right away, when it was still reasonably tidy, because if you wait until you can't find anything any more, cleaning your room will be much harder, much more annoying and take much longer.
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: PlatformGuy! V0.2

Post by kikito »

WolfNinja2 wrote:right now I want to understand fundementals and all that jazz, not focus on pretty coding :/
What these people are talking about are not simply embellishments. I'm going to make a metaphor with building a house. (Which is kindof a louse example, but I think I'll do).

When you build a house, you start with its foundations. Everything you "add" on top of them relies on them being solid enough. If your foundations are not very good, your house might "hold" for a little while, but the risk of having the walls "collapse" increases with every brick you add.

Similarly, you want to use the appropriate materials. If you build the roof with wood planks, but you don't varnish them, they'll rot with the first rain. If you use plaster to glue your bricks instead of cement, then your walls will crumble under the slightest pressure. And in time, your house will collapse.

The foundations of a program is the structure. The main "components". They must be well defined, and well separated. They must communicate through very concrete channels. Otherwise, they will not be a good foundation to build upon - you will have to abandon your project (the house will collapse).

Appropiate materials are things like variable names, indentation, and also libraries used. Choosing good variable names is very difficult, and sometimes requires time. I often spend entire minutes just pondering about the name of a variable. It's worth it; I'd rather spend those minutes giving the variable the exact right name than debugging a code filled with lousy-named variables.

The editor you use is also important. Lots of decent editors are able to auto-indent source code properly. Use one of those.
When I write def I mean function.
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: PlatformGuy! V0.2

Post by WolfNinja2 »

kikito wrote:
WolfNinja2 wrote:right now I want to understand fundementals and all that jazz, not focus on pretty coding :/
What these people are talking about are not simply embellishments. I'm going to make a metaphor with building a house. (Which is kindof a louse example, but I think I'll do).

When you build a house, you start with its foundations. Everything you "add" on top of them relies on them being solid enough. If your foundations are not very good, your house might "hold" for a little while, but the risk of having the walls "collapse" increases with every brick you add.

Similarly, you want to use the appropriate materials. If you build the roof with wood planks, but you don't varnish them, they'll rot with the first rain. If you use plaster to glue your bricks instead of cement, then your walls will crumble under the slightest pressure. And in time, your house will collapse.

The foundations of a program is the structure. The main "components". They must be well defined, and well separated. They must communicate through very concrete channels. Otherwise, they will not be a good foundation to build upon - you will have to abandon your project (the house will collapse).

Appropiate materials are things like variable names, indentation, and also libraries used. Choosing good variable names is very difficult, and sometimes requires time. I often spend entire minutes just pondering about the name of a variable. It's worth it; I'd rather spend those minutes giving the variable the exact right name than debugging a code filled with lousy-named variables.

The editor you use is also important. Lots of decent editors are able to auto-indent source code properly. Use one of those.
I use Notepad++ and it makes organizing a bit easier, but I see what you mean. I guess I better start taking your guys advice.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: PlatformGuy! V0.2

Post by Puzzlem00n »

WolfNinja2 wrote:You're right, I do want to expand a LOT, but I don't think he's talking about indentation really. I think he means how my coding works. BUT, if he's talking about the indentation I can do that no problem! In fact, I'm going to do it either way now that you mention it xD

-Wolf
Yes, yess I am talking about how it works. While what Robin and kikito, the almighty defenders of all that is this forum (which, when you think about it, is just this forum :ehem: ), are definitely right in all that, this doesn't make any sense at all.

Code: Select all

if love.keyboard.isDown("up") and
onGround == true or
love.keyboard.isDown("up") and
jumping == true then
Even when you fix this semantically:

Code: Select all

if love.keyboard.isDown("up") and onGround == true or love.keyboard.isDown("up") and jumping == true then
Then that's still ridiculously bizarre. If it runs whether you're jumping or not, then why not run it whenever "up" is held? Or should it not run when you're falling? *sigh*... I'm losing my mind a bit here.

And as far as I can tell, this thing thinks from this:

Code: Select all

function playerupdate(dt)
	if maploaded == true then
	
	local dt = math.min(dt,0.1)

	timedSpeed = player.speed * dt
	timedyvel = player.yvel * dt
	player.yvel = player.yvel + player.grav * dt
	
	--Left and Right Collision
	if love.keyboard.isDown("left") then
		if mapCollide(player.x - timedSpeed, player.y + 1) or mapCollide(player.x - timedSpeed, player.y + player.h - 1) then
			player.x = math.floor(player.x / tiledivisor) * tiledivisor
		else
			player.x = player.x - timedSpeed
		end
	end
	if love.keyboard.isDown("right") then
		if mapCollide(player.x + timedSpeed + player.w, player.y + 1) or mapCollide(player.x + timedSpeed + player.w, player.y + player.h - 1) then
			player.x = (math.floor((player.x + player.w + timedSpeed) / tiledivisor) * tiledivisor) - player.w
		else
			player.x = player.x + timedSpeed
		end
	end
   
   --Up and Down Collision
	if math.abs(timedyvel) < tiledivisor then j = math.abs(timedyvel) else j = tiledivisor end
	if timedyvel > 0 then negateit = 1 else negateit = -1 end
	if mapCollide(player.x + 1, player.y + player.h + j*negateit) or mapCollide(player.x + player.w - 1, player.y + player.h + j*negateit) then
		player.y =(math.floor((player.y + player.h + j) / tiledivisor) * tiledivisor) - player.h
		player.yvel = 0
		onGround = true
		storedY = 0
	elseif mapCollide(player.x + 1, player.y + j*negateit) or mapCollide(player.x + player.w - 1, player.y + j*negateit) then
		player.y = math.floor(player.y / tiledivisor) * tiledivisor
		player.yvel = 0
	else
		player.y = player.y + j*negateit
		onGround = false
		end
		function skin_change(key)
		--Skin Change
	if love.keyboard.isDown("s") then
		if P == love.graphics.newImage("player1.png") then
		P = love.graphics.newImage("player2.png")
		end
		elseif P == love.graphics.newImage("player2.png") then
		P = love.graphics.newImage("player1.png")
			end
		end
	end
end
That function skin change is inside playerupdate... That is not what you want. There is also an extra end in that skin function that should be somewhere else. I'd normally not just give it to you, but it's so messed up, I'd be doing you and myself a disservice not to. Basically, you should get rid of that function completely, and move that end.

Code: Select all

function playerupdate(dt)
	if maploaded == true then
		local dt = math.min(dt,0.1)

		timedSpeed = player.speed * dt
		timedyvel = player.yvel * dt
		player.yvel = player.yvel + player.grav * dt
		
		--Left and Right Collision
		if love.keyboard.isDown("left") then
			if mapCollide(player.x - timedSpeed, player.y + 1) or mapCollide(player.x - timedSpeed, player.y + player.h - 1) then
				player.x = math.floor(player.x / tiledivisor) * tiledivisor
			else
				player.x = player.x - timedSpeed
			end
		end
		if love.keyboard.isDown("right") then
			if mapCollide(player.x + timedSpeed + player.w, player.y + 1) or mapCollide(player.x + timedSpeed + player.w, player.y + player.h - 1) then
				player.x = (math.floor((player.x + player.w + timedSpeed) / tiledivisor) * tiledivisor) - player.w
			else
				player.x = player.x + timedSpeed
			end
		end
	   
	   --Up and Down Collision
		if math.abs(timedyvel) < tiledivisor then j = math.abs(timedyvel) else j = tiledivisor end
		if timedyvel > 0 then negateit = 1 else negateit = -1 end
		if mapCollide(player.x + 1, player.y + player.h + j*negateit) or mapCollide(player.x + player.w - 1, player.y + player.h + j*negateit) then
			player.y =(math.floor((player.y + player.h + j) / tiledivisor) * tiledivisor) - player.h
			player.yvel = 0
			onGround = true
			storedY = 0
		elseif mapCollide(player.x + 1, player.y + j*negateit) or mapCollide(player.x + player.w - 1, player.y + j*negateit) then
			player.y = math.floor(player.y / tiledivisor) * tiledivisor
			player.yvel = 0
		else
			player.y = player.y + j*negateit
			onGround = false
			end
		if love.keyboard.isDown("s") then
			if P == love.graphics.newImage("player1.png") then
				P = love.graphics.newImage("player2.png")
			elseif P == love.graphics.newImage("player2.png") then
				P = love.graphics.newImage("player1.png")
			end
		end
	end
end
You can tell this works because now pressing 's' produces the error that there's no other skin to change to. Ironic, an error showing it works, eh? :megagrin:
I LÖVE, therefore I am.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: PlatformGuy! V0.2

Post by Robin »

(I didn't actually look at the code, so this is new for me.)

Oh, wow:

Code: Select all

         if P == love.graphics.newImage("player1.png") then
            P = love.graphics.newImage("player2.png")
         elseif P == love.graphics.newImage("player2.png") then
            P = love.graphics.newImage("player1.png")
         end
This is all kinds of messed up.

A better way would be:

Code: Select all

         if P == player_img1 then
            P = player_img2
         elseif P == player_img2 then
            P = player_img1
         end
And have in love.load:

Code: Select all

player_img1 = love.graphics.newImage("player1.png")
player_img2 = love.graphics.newImage("player2.png")
That way you don't create a new image every time you press "s". Plus your way didn't even work (IIRC), because love.graphics.newImage will return a new reference and therefore P == love.graphics.newImage(...) will never be true.
Help us help you: attach a .love.
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: PlatformGuy! V0.2

Post by WolfNinja2 »

Robin, this is exactly what I've been lying in bed thinking about how it should be done. I've just never needed to mess with it because no one submitted a skin to put in the game(so why even make it an option) AND on the topic of my jumping function puzz, it NEEDS to have the variable on ground and if it's jumping because then we can cut off the variable 'jumping' so it's false, thus stopping the jump. It works in my head XD.
And I didn't even realize that that function got stuck inside my player update function O,o

-Wolf
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Yay!

Post by WolfNinja2 »

I JUST finished my OWN level two xD
It's 6am and I just screamed 'YEA' while my arms went flying up.
Have you guys beat the game? :D

-Wolf
YeOleBluegrass
Prole
Posts: 3
Joined: Sat Oct 13, 2012 12:03 am
Location: Votorantim, São Paulo, Brasil

Re: PlatformGuy! V0.2

Post by YeOleBluegrass »

WolfNinja2 wrote:I JUST finished my OWN level two xD
It's 6am and I just screamed 'YEA' while my arms went flying up.
Have you guys beat the game? :D

-Wolf
I don't have skills to beat the game -.-
Good work getting this far, future starter! That said, if you are simple-minded, old, or irradiated in such a way that the future should not start with you, please return to your primitive tribe and send back someone better-qualified for testing.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: PlatformGuy! V0.2

Post by Puzzlem00n »

Bumping... More bumping...

Oh, and no, not really. Been too busy messing with the code. :)
I LÖVE, therefore I am.
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: PlatformGuy! V0.2

Post by WolfNinja2 »

Puzzlem00n wrote:Bumping... More bumping...

Oh, and no, not really. Been too busy messing with the code. :)
Puzzle, I didn't mean that to bump, I literally FINALLY got past that stupid floating lave (which is now a spike btw :D ) and wanted to know if anyone else could do it... because I tried for over an hour. XD

-Wolf
Post Reply

Who is online

Users browsing this forum: No registered users and 60 guests