I am Tookman, a high school student that doesn't have much experience coding games, but I have experience with just general coding, can someone give me the coding to a simple game so that I can study it to understand more about game coding?
Hello, sorry I haven't been on a lot lately, I was having troubles with my adobe flash player. I got the issue fixed but i do not know why my square won't move. this is my current program.
C:\Users\Matthew\Documents\Videogame!\Main.as
package
{ import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; public class Main extends Sprite { private var aDown:Boolean = false; private var dDown:Boolean = false; private var charlayer = new player (); public function Main():void { char.x = 500; char.y = 300; addChild(char); stage.addEventListener(Event.ENTER_FRAME, keys); stage.addEventListener(KeyboardEvent.Event.KEY_DOWN, keysdown); stage.addEventListener(KeyboardEvent.Event.KEY_UP, keysup); } public function keys(e:Event):void { if (aDown) = true char.x - 5; if (dDown) = true char.x + 5; } public function keysdown(e:KeyboardEvent):void { if (e.keyCode == 65) aDown = true; if (e.keyCode == 68) dDown = true; } public function keysup(e:KeyboardEvent):void { if (e.keyCode == 65) aDown = false; if (e.keyCode == 68) dDown = false; } }
And this is my player ( the square);
package
{ import flash.display.MovieClip; public class player extends MovieClip { public function player() { this.graphics.beginFill(0xfff000, 1); this.graphics.drawRect(this.x, this.y, 10, 10); this.graphics.endFill (); }
so, weirdlike, I edited my code to have your switch and now it is saying that it needs to have a identifier in lines 22 and 24... why does it need this? And what does it need?
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
public class Main extends Sprite
{
private var aDown:Boolean = false;
private var dDown:Boolean = false;
private var charlayer = new player ();
public function Main():void
{
char.x = 500;
char.y = 300;
addChild(char);
stage.addEventListener(Event.ENTER_FRAME, keys);
stage.addEventListener(KeyboardEvent.Event.KEY_DOWN, keysdown);
stage.addEventListener(KeyboardEvent.Event.KEY_UP, keysup);
}
public function keys(e:Event):void
{
if (aDown) = true
char.x - 5;
if (dDown) = true
char.x + 5;
}
public function keysdown(e:KeyboardEvent):void
{ switch (e.keyCode) { case Keyboard.A: { aDown = true; break; } }
}
public function keysup(e:KeyboardEvent):void
{ switch (e.keyCode) { case Keyboard.A: { aDown = false; break; } }
}
}
now there's two more property errors, keyboard and event through...., here's my code;
package
{ import flash.display.Sprite; import flash.events.Event; import flash.events.KeyboardEvent; public class Main extends Sprite
{ private var aDown:Boolean = false; private var dDown:Boolean = false; private var char : player; public function Main():void
{ char = new player(); char.x = 500; char.y = 300; addChild(char); stage.addEventListener(Event.ENTER_FRAME, keys); stage.addEventListener(KeyboardEvent.Event.KEY_DOWN, keysdown); stage.addEventListener(KeyboardEvent.Event.KEY_UP, keysup);
}
public function keys(e:Event):void
{
if (aDown == true)
char.x - 5;
if (dDown == true)
char.x + 5;
}
public function keysdown(e:KeyboardEvent):void
{ switch (e.keyCode) { case Keyboard.A: { aDown = true; break; } }
}
public function keysup(e:KeyboardEvent):void
{ switch (e.keyCode) { case Keyboard.A: { aDown = false; break; } }
}
}