Jump to content
  • Advertisement
Sign in to follow this  
Jesse Dager

Speaking of disasters...

This topic is 1485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So for last weeks GDNJam, I added alot of messy, inefficient, and all around ugly code to my engine just for the sake of having "working" features in the quickest time. That lead to some very... interesting lines of code.

For example:

 

I have a struct "TEXT" that holds a string, color code, id number, time for timed deletion, and the x, y position of the text. These TEXT types are then stored in a vector to be later referenced and edited by their ID number. Well, when it came down to deleting them, no matter what I tried, I couldn't get a clean way to compile. That's when I resorted to:

gui->editText(key, " ");

That's right. Instead of freeing the memory and deleting it, I actually changed the value of JUST THE STRING to a space.

 

And another one from the engine in the AI character code this time:

Character* Scene::getCharacter(int id)
{
	for(std::vector<Character *>::iterator it = c.begin(); it < c.end(); it++)
	{
		if((*it)->id == id)
		{
			return (*it);
		}
	}
}

Please note the lack of return if the id doesn't exist... 

 

and don't even get me STARTED on the startup.lua file... 

if aiTime >= 2 then
			aiTime = 0
			local pX = scene:getPlayer():getX()
			local pY = scene:getPlayer():getY()
			local pD = scene:getPlayer():getDir()
			if T1:getMeta("alive") == "true" then
				if collide(T1:getX(), T1:getY(), pX, pY, 20, 20) then
					System_run("Scripts/die.lua")
				end
				local deltaX = 0
				local deltaY = 0
				if pD == UP then
					if T1:getY() > pY then
						deltaY = deltaY - 1
						if T1:getX() > pX then
							deltaX = deltaX - 1
						end
						if T1:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == DOWN then
					if T1:getY() < pY then
						deltaY = deltaY + 1
						if T1:getX() > pX then
							deltaX = deltaX - 1
						end
						if T1:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == LEFT then
					if T1:getX() > pX then
						deltaX = deltaX - 1
						if T1:getY() > pY then
							deltaY = deltaY - 1
						end
						if T1:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				if pD == RIGHT then
					if T1:getX() < pX then
						deltaX = deltaX + 1
						if T1:getY() > pY then
							deltaY = deltaY - 1
						end
						if T1:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				T1:setPos(T1:getX()+deltaX, T1:getY()+deltaY)
			end
			if T2:getMeta("alive") == "true" then
				if collide(T2:getX(), T2:getY(), pX, pY, 20, 20) then
					System_run("Scripts/die.lua")
				end
				local deltaX = 0
				local deltaY = 0
				if pD == UP then
					if T2:getY() > pY then
						deltaY = deltaY - 1
						if T2:getX() > pX then
							deltaX = deltaX - 1
						end
						if T2:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == DOWN then
					if T2:getY() < pY then
						deltaY = deltaY + 1
						if T2:getX() > pX then
							deltaX = deltaX - 1
						end
						if T2:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == LEFT then
					if T2:getX() > pX then
						deltaX = deltaX - 1
						if T2:getY() > pY then
							deltaY = deltaY - 1
						end
						if T2:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				if pD == RIGHT then
					if T2:getX() < pX then
						deltaX = deltaX + 1
						if T2:getY() > pY then
							deltaY = deltaY - 1
						end
						if T2:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				T2:setPos(T2:getX()+deltaX, T2:getY()+deltaY)
			end
			if T3:getMeta("alive") == "true" then
				if collide(T3:getX(), T3:getY(), pX, pY, 20, 20) then
					System_run("Scripts/die.lua")
				end
				local deltaX = 0
				local deltaY = 0
				if pD == UP then
					if T3:getY() > pY then
						deltaY = deltaY - 1
						if T3:getX() > pX then
							deltaX = deltaX - 1
						end
						if T3:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == DOWN then
					if T3:getY() < pY then
						deltaY = deltaY + 1
						if T3:getX() > pX then
							deltaX = deltaX - 1
						end
						if T3:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == LEFT then
					if T3:getX() > pX then
						deltaX = deltaX - 1
						if T3:getY() > pY then
							deltaY = deltaY - 1
						end
						if T3:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				if pD == RIGHT then
					if T3:getX() < pX then
						deltaX = deltaX + 1
						if T3:getY() > pY then
							deltaY = deltaY - 1
						end
						if T3:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				T3:setPos(T3:getX()+deltaX, T3:getY()+deltaY)
			end
			if T4:getMeta("alive") == "true" then
				if collide(T4:getX(), T4:getY(), pX, pY, 20, 20) then
					System_run("Scripts/die.lua")
				end
				local deltaX = 0
				local deltaY = 0
				if pD == UP then
					if T4:getY() > pY then
						deltaY = deltaY - 1
						if T4:getX() > pX then
							deltaX = deltaX - 1
						end
						if T4:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == DOWN then
					if T4:getY() < pY then
						deltaY = deltaY + 1
						if T4:getX() > pX then
							deltaX = deltaX - 1
						end
						if T4:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == RIGHT then
					if T4:getX() < pX then
						deltaX = deltaX + 1
						if T4:getY() > pY then
							deltaY = deltaY - 1
						end
						if T4:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				if pD == LEFT then
					if T4:getX() > pX then
						deltaX = deltaX - 1
						if T4:getY() > pY then
							deltaY = deltaY - 1
						end
						if T4:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				T4:setPos(T4:getX()+deltaX, T4:getY()+deltaY)
			end
		end

All of these things have been fixed since their creation, but I figured they were noteworthy for posting here.

Any ugly, disastrous code that you guys have from a contest or timed event?

Edited by sethhope

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!