Recent posts by holgeir564 on Kongregate

Flag Post

Topic: Game Programming / Art for your games

So I am not good at drawing or animating but I can program! Are there any sites you guys could direct me to where I can get art without collaborating?

 
Flag Post

Topic: Game Programming / [AS3] Tile engine problem

Guys I solved it!
maybe not the best solve but here it is:


                private function boxHit(targ1:MovieClip,targ2:MovieClip)
		{
/*
===============================================================================
This collision decection moves target 1 while target 2 stays put. 
only one requirement for target 1 which is to have the variables lastX 
and lastY which represents the last X and Y position. 
===============================================================================
*/

			var returnString = "";
			var ySideLast = Math.round(Math.abs(targ1.lastY-targ2.y)/(targ1.lastY-targ2.y))
			var xSideLast = Math.round(Math.abs(targ1.lastX-targ2.x)/(targ1.lastX-targ2.x))
			if (ySideLast != 1 && ySideLast != -1)
			{
				ySideLast = 1;
			}
			if (xSideLast != 1 && xSideLast != -1)
			{
				xSideLast = 1;
			}
			var yDefOffset = 4
			var yDef = ((targ1.lastY+(((targ1.height/2)-yDefOffset)*-ySideLast))*ySideLast)+((targ2.y+(((targ2.height/2)-yDefOffset)*ySideLast))*-ySideLast);
			var lastXDef = ((targ1.lastX+((targ1.width/2)*-xSideLast))*xSideLast)+((targ2.x+((targ2.width/2)*xSideLast))*-xSideLast);
			var currXDef = ((targ1.lastX+((targ1.width/2)*-xSideLast))*xSideLast)+((targ1.x+((targ1.width/2)*-xSideLast))*-xSideLast);
			var lastYDef = ((targ1.lastY+((targ1.height/2)*-ySideLast))*ySideLast)+((targ2.y+((targ2.height/2)*ySideLast))*-ySideLast);
			var currYDef = ((targ1.lastY+((targ1.height/2)*-ySideLast))*ySideLast)+((targ1.y+((targ1.height/2)*-ySideLast))*-ySideLast);
			if (lastXDef<currXDef && lastYDef<currYDef)
			{
				if (lastXDef>yDef)
				{
					targ1.x-=(((targ1.x+((targ1.width/2)*-xSideLast))*xSideLast)+((targ2.x+((targ2.width/2)*xSideLast))*-xSideLast))*xSideLast;
					returnString = "onWall";
				}
				else
				{
					targ1.y-=(((targ1.y+((targ1.height/2)*-ySideLast))*ySideLast)+((targ2.y+((targ2.height/2)*ySideLast))*-ySideLast))*ySideLast;
					if (ySideLast == 1)
					{
						returnString = "onCeiling";
					}
					else
					{
						returnString = "onGround";
					}
				}
			}
			return returnString;
		}

 
Flag Post

Topic: Game Programming / [AS3] Tile engine problem

It didn’t fix it :S

 
Flag Post

Topic: Game Programming / [AS3] Tile engine problem

I am making a tile engine and have run into a strange problem. when I go right on the ground everything is ok, but when I go left on the ground the player stutters. I don’t get why and it is confusing :S

Here is a link to the swf:
http://www.newgrounds.com/dump/item/465a849074c3764d082d5f12a99fc5b8

If looking at the code could help here is the basic engine:


                private function boxHit(targ1:MovieClip,targ2:MovieClip)
		{
/*
===============================================================================
This collision decection moves target 1 while target 2 stays put. 
only one requirement for target 1 which is to have the variables lastX 
and lastY which represents the last X and Y position. 
===============================================================================
*/

			var returnString = "";
			var ySideLast = Math.abs(targ1.lastY-targ2.y)/(targ1.lastY-targ2.y);
			var xSideLast = Math.abs(targ1.lastX-targ2.x)/(targ1.lastX-targ2.x);
			if (ySideLast != 1 && ySideLast != -1)
			{
				ySideLast = 1;
			}
			if (xSideLast != 1 && xSideLast != -1)
			{
				xSideLast = 1;
			}
			var lastXDef = ((targ1.lastX+((targ1.width/2)*-xSideLast))*xSideLast)+((targ2.x+((targ2.width/2)*xSideLast))*-xSideLast);
			var currXDef = ((targ1.lastX+((targ1.width/2)*-xSideLast))*xSideLast)+((targ1.x+((targ1.width/2)*-xSideLast))*-xSideLast);
			var lastYDef = ((targ1.lastY+((targ1.height/2)*-ySideLast))*ySideLast)+((targ2.y+(((targ2.height)/2)*ySideLast))*-ySideLast);
			var currYDef = ((targ1.lastY+((targ1.height/2)*-ySideLast))*ySideLast)+((targ1.y+((targ1.height/2)*-ySideLast))*-ySideLast);
			trace(currXDef+" vs "+currYDef);
			if (lastXDef<currXDef && lastYDef<currYDef)
			{
				if (lastXDef>lastYDef)
				{
					targ1.x-=(((targ1.x+((targ1.width/2)*-xSideLast))*xSideLast)+((targ2.x+((targ2.width/2)*xSideLast))*-xSideLast))*xSideLast;
					returnString = "onWall";
				}
				else
				{
					targ1.y-=(((targ1.y+((targ1.height/2)*-ySideLast))*ySideLast)+((targ2.y+((targ2.height/2)*ySideLast))*-ySideLast))*ySideLast;
					if (ySideLast == 1)
					{
						returnString = "onCeiling";
					}
					else
					{
						returnString = "onGround";
					}
				}
			}
			return returnString;
		}

Thanks in advance :D:D

 
Flag Post

Topic: Game Design / Sound Effects

omg Audacity is Awesome!

 
Flag Post

Topic: Game Design / Sound Effects

Don’t really know where to post this so I posted it here :D
Where do you guys find sound effects for your games?
or do you make them yourselves?

 
Flag Post

Topic: Game Programming / [AS3] KeyCodes not working

This is the code that handles the keyArray. It contains all the keycodes of the keys that are pressed down.


//adds keys that are down to keyArray
		public function addKey(e:KeyboardEvent):void
		{
			if (keyArray.indexOf(e.keyCode) < 0)
			{
				keyArray.push(e.keyCode);
			}
		}
		//removes keys that are not down from keyArray
		public function removeKey(e:KeyboardEvent):void
		{
			if (keyArray.indexOf(e.keyCode) >= 0)
			{
				keyArray.splice(keyArray.indexOf(e.keyCode),1);
			}
		}

And then there are if statements that check the array and use the information from it:


//if key is up
			if (keyArray.indexOf(38) < 0)
			{
				upKey=false;
			}
			if (keyArray.indexOf(40) < 0)
			{
				downKey=false;
			}
			if (keyArray.indexOf(37) < 0)
			{
				leftKey=false;
			}
			if (keyArray.indexOf(39) < 0)
			{
				rightKey=false;
			}
			if (keyArray.indexOf(16) < 0)
			{
				shiftKey=false;
			}
			if (keyArray.indexOf(80) < 0)
			{
				pauseKey=false;
			}

			//if key is down
			if (keyArray.indexOf(38) >= 0)
			{
				upKey=true;
			}
			if (keyArray.indexOf(40) >= 0)
			{
				downKey=true;
			}
			if (keyArray.indexOf(37) >= 0)
			{
				leftKey=true;
			}
			if (keyArray.indexOf(39) >= 0)
			{
				rightKey=true;
			}
			if (keyArray.indexOf(16) >= 0)
			{
				shiftKey=true;
			}
			if (keyArray.indexOf(80) >= 0)
			{
				pauseKey = true;
			}

 
Flag Post

Topic: Game Programming / [AS3] KeyCodes not working

So Im trying to make a pause menu for my game and want to use the “p”-key. The keycode for that is 80. I use the same code for the pause key as the arrow . The arrow keys work fine but the pause key wont respond. What am I doing wrong? btw here is the basic code:


if (keyArray.indexOf(80) >= 0)
{
	pauseKey = true;
}
if (keyArray.indexOf(80) < 0)
{
	pauseKey=false;
}
trace(pauseKey);

 
Flag Post

Topic: Game Design / Replayability

Some super hard games give me the replayability because when I come back to such a game it is still hard. The worlds hardest game is a good exaple of this. I have never really beaten it but I come back to it again and again beating the same levels for fun. Do you feel the same about hard games or do they just frustrate you?

 
Flag Post

Topic: Game Programming / [AS3] Better code for mass Buttons (solved)

Thanks for the tip it worked :D

 
Flag Post

Topic: Game Programming / [AS3] Better code for mass Buttons (solved)

There has to be a better way than this to make multiable button EventListener (@case “PlayMenu”):


switch (useMenu)
			{
				case "InsMenu" :
					insMenu = new InsMenu();
					addChild(insMenu);
					insMenu.BackButton.addEventListener(MouseEvent.CLICK,onBackButtonClick);
					break;
				case "PlayMenu" :
					playMenu = new PlayMenu();
					addChild(playMenu);
					playMenu.BackButton.addEventListener(MouseEvent.CLICK,onBackButtonClick);
					playMenu.Level1Button.addEventListener(MouseEvent.CLICK,onLevel1Click);
					playMenu.Level2Button.addEventListener(MouseEvent.CLICK,onLevel2Click);
					playMenu.Level3Button.addEventListener(MouseEvent.CLICK,onLevel3Click);
					playMenu.Level4Button.addEventListener(MouseEvent.CLICK,onLevel4Click);
					playMenu.Level5Button.addEventListener(MouseEvent.CLICK,onLevel5Click);
					playMenu.Level6Button.addEventListener(MouseEvent.CLICK,onLevel6Click);
					playMenu.Level7Button.addEventListener(MouseEvent.CLICK,onLevel7Click);
					playMenu.Level8Button.addEventListener(MouseEvent.CLICK,onLevel8Click);
					playMenu.Level9Button.addEventListener(MouseEvent.CLICK,onLevel9Click);
					break;
				case "MainMenu" :
					mainMenu = new MainMenu();
					addChild(mainMenu);
					mainMenu.PlayButton.addEventListener(MouseEvent.CLICK,onPlayButtonClick);
					mainMenu.InsButton.addEventListener(MouseEvent.CLICK,onInsButtonClick);
					break;
				default :
					trace("error #3: no menu found");
					break;
			}

Thanks in advance :D

 
Flag Post

Topic: Game Programming / [AS3] Having some #1009 problems

So here is my code:


package 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	public class Enemy extends MovieClip
	{
		public var statx:Number;
		public var staty:Number;

		//misc vars
		public var typ:Number;//keeps track of what type clip is
		public var shoots:Boolean;
		public var shotRotation:Number;
		public var shotTimer:Timer;
		public var shot:Shot;
		public var xOffset:Number;//where shots spawn compared to clip posision
		public var yOffset:Number;//where shots spawn compared to clip posision

		//movent vars
		public var xspeed:Number;
		public var yspeed:Number;
		public function Enemy(statx,staty,typ)
		{
			x=statx;
			y=staty;
			this.typ=typ;
			gotoAndStop(typ);
			switch (typ)
			{
				case 1 :
					this.xspeed=-5;
					this.yspeed=0;
					this.shoots = false;
					break;
				case 2 :
					this.xspeed=-6;
					this.yspeed=0;
					xOffset = -(width/2);
					yOffset = 0;
					shotTimer = new Timer(1000);
					shotTimer.addEventListener(TimerEvent.TIMER,onShoot);
					shotTimer.start();
					break;
				default :
					trace("error #1: enemyType dose not exist");
					break;
			}
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		public function onAddedToStage(event:Event)
		{
			dispatchEvent(new Event("enemyCreated",true));
			stage.addEventListener(Event.REMOVED_FROM_STAGE,onRemoved);
		}
		public function onRemoved(event:Event)
		{
			shotTimer.stop();
		}
		public function onShoot(timerEvent:TimerEvent)//(##)
		{
			shot = new Shot(x+xOffset,y+yOffset,180);
			parent.addChild(shot);
		}
		public function onMove():void
		{
			x+= xspeed;
			y+= yspeed;
		}
	}
}

At (##) it spawns a shot which is shot by the enemy. The first enemy goes across the stage without anything happening. But when the second enemy goes on stage the output gives me this every time it shoots:


TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at Enemy/onShoot()
	at flash.utils::Timer/_timerDispatch()
	at flash.utils::Timer/tick()

This error dose not show up when the onShoot function is empty. I don’t know what I am doing wrong :S

Thanks in advance :D

 
Flag Post

Topic: Game Programming / [AS3] RemoveChild function :O

I got your point :) And it worked ;)

 
Flag Post

Topic: Game Programming / [AS3] RemoveChild function :O

3.I see what you mean. Instead of like I have it you would have:


public function spawnShot(var shotX,var shotY,var shotRotation):void
{
	shot = new Shot(shotX,shotY,shotRotation);
	addChild(shot);
}

Is that right?

 
Flag Post

Topic: Game Programming / [AS3] RemoveChild function :O

1.It works
2.It works
3.Not following you…?

(I’m new to AS3 so :D)

 
Flag Post

Topic: Game Programming / [AS3] RemoveChild function :O

Thanks that worked :D

 
Flag Post

Topic: Game Programming / [AS3] RemoveChild function :O

That little snippet of code is in the same object where I addChild shot. Here the whole thing is:


package 
{
	import flash.display.MovieClip;
	import flash.events.TimerEvent;
	import flash.events.Event;
	import flash.utils.Timer;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	public class GameScreen extends MovieClip
	{
		//defning movieClips
		public var player:Player;
		public var shot:Shot;

		//defining Timers
		public var fastTick:Timer;//fast timer which handels player movment and other stage movments

		//defining keyboard vars
		public var keyArray:Array=new Array;
		public var upKey:Boolean;
		public var downKey:Boolean;
		public var rightKey:Boolean;
		public var leftKey:Boolean;
		public var spaceKey:Boolean;

		//shot startposisions
		public var shotX:Number = 0;
		public var shotY:Number = 0;
		public var shotRotation:Number = 0;
		public function GameScreen()
		{
			addEventListener(Event.ADDED_TO_STAGE,onGetStage);

			player = new Player(100,100);
			addChild(player);

			fastTick = new Timer(10);
			fastTick.addEventListener(TimerEvent.TIMER,onFastTick);
			fastTick.start();
		}
		public function onFastTick(timerEvent:TimerEvent):void
		{
			//if key is up
			if (keyArray.indexOf(38) < 0)
			{
				upKey=false;
			}
			if (keyArray.indexOf(40) < 0)
			{
				downKey=false;
			}
			if (keyArray.indexOf(37) < 0)
			{
				leftKey=false;
			}
			if (keyArray.indexOf(39) < 0)
			{
				rightKey=false;
			}
			if (keyArray.indexOf(32) < 0)
			{
				spaceKey=false;
			}

			//if key is down
			if (keyArray.indexOf(38) >= 0)
			{
				upKey=true;
			}
			if (keyArray.indexOf(40) >= 0)
			{
				downKey=true;
			}
			if (keyArray.indexOf(37) >= 0)
			{
				leftKey=true;
			}
			if (keyArray.indexOf(39) >= 0)
			{
				rightKey=true;
			}
			if (keyArray.indexOf(32) >= 0)
			{
				spaceKey=true;
			}
			trace(keyArray);

			player.onMove(upKey,downKey,rightKey,leftKey,spaceKey);//this function lests the player know which keys are down and enables movment

			if (spaceKey == true)
			{
				spawnShot(player.x,player.y,90);
			}
			for (var i in Shot.shotz)
			{
				Shot.shotz[i].x += Shot.shotz[i].xspeed;
				Shot.shotz[i].y += Shot.shotz[i].yspeed;
				if (Shot.shotz[i].y>500||Shot.shotz[i].y<0||Shot.shotz[i].x<0||Shot.shotz[i].x>700)
				{
					removeChild(Shot.shotz[i]);
				}
			}

		}
		//spawns shots
		public function spawnShot(shotX,shotY,shotRotation):void
		{
			shot = new Shot(shotX,shotY,shotRotation);
			addChild(shot);
		}
		//Setup keys
		public function onGetStage(event:Event)
		{
			stage.addEventListener(KeyboardEvent.KEY_UP,removeKey);
			stage.addEventListener(KeyboardEvent.KEY_DOWN,addKey);

		}
		//adds keys that are down to keyArray
		public function addKey(e:KeyboardEvent):void
		{
			if (keyArray.indexOf(e.keyCode) < 0)
			{
				keyArray.push(e.keyCode);
			}
		}
		//removes keys that are not down from keyArray
		public function removeKey(e:KeyboardEvent):void
		{
			if (keyArray.indexOf(e.keyCode) >= 0)
			{
				keyArray.splice(keyArray.indexOf(e.keyCode),1);
			}
		}
	}
}

 
Flag Post

Topic: Game Programming / [AS3] RemoveChild function :O

How do I then remove it?

 
Flag Post

Topic: Game Programming / [AS3] RemoveChild function :O

This is my code:


for (var i in Shot.shotz)
			{
				Shot.shotz[i].x += Shot.shotz[i].xspeed;
				Shot.shotz[i].y += Shot.shotz[i].yspeed;
				if (Shot.shotz[i].y>500||Shot.shotz[i].y<0||Shot.shotz[i].x<0||Shot.shotz[i].x>700)
				{
					removeChild(Shot.shotz[i]);// (*)
				}
			}

At (*) I am trying to make the shot disappear, but flash traces:


ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
	at flash.display::DisplayObjectContainer/removeChild()
	at GameScreen/onFastTick()
	at flash.utils::Timer/_timerDispatch()
	at flash.utils::Timer/tick()

What am I doing wrong here?
Thanks in advance :D

 
Flag Post

Topic: Game Programming / Copy and pasting

Seems like a great program! But I have a mac and I can’t find it for mac :/

 
Flag Post

Topic: Game Programming / Copy and pasting

So this Christmas vacation I want to try to go bananas and program a lot. I also want get into good habits with my “mechanics” when programing. So I wanted to ask if you use copy paste (in your own code) when coding or do you type everything in by hand? If you have other tips they would be appreciated :D

 
Flag Post

Topic: Game Programming / [AS3] When stuff is undefined (Solved)

Solved it! thanks :D

 
Flag Post

Topic: Game Programming / [AS3] When stuff is undefined (Solved)

LoL I didn’t define currentLevel :P

 
Flag Post

Topic: Game Programming / [AS3] When stuff is undefined (Solved)

This is my code, take note of (#) and (##):


package 
{
	import flash.display.MovieClip;
	public class Doors extends MovieClip
	{
		public var door:Door;

		public var currentLevel:Number;
		//Doorlevel vars where doors spawn and where they lead
		static var doorsLevel1:Array = [];
		static var doorsLevel2:Array = [];
		static var doorsArray:Array = [doorsLevel1,doorsLevel2];
		public function Doors(currentLevel)
		{
			defineDoorPlacement();
			makeDoors(currentLevel);
		}
		public function defineDoorPlacement():void
		{
			doorsLevel1 = [1,2,3];
			doorsLevel2 = [1,2,3];
		}
		public function makeDoors(currentLevel):void
		{
			trace(doorsArray[currentLevel-1]) // (#)
			var useLevel = doorsArray[currentLevel-1];
			trace(useLevel[1]); // (##)
		}
	}
}

At (#) it traces a empty array an at (##) it traces undefined. Why is everything so undefined!

Thanks in advance.

 
Flag Post

Topic: Game Programming / [AS3] Variable access (SOLVED)

Thanks! it worked! :D