ForumsProgramming ForumNew Programmer

128 44314
Tookman
offline
Tookman
87 posts
Nomad

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?

  • 128 Replies
Tookman
offline
Tookman
87 posts
Nomad

wait!

weirdlike
offline
weirdlike
1,299 posts
Prince

char.x -= 5;

or

char.x = char.x - 5;

weirdlike
offline
weirdlike
1,299 posts
Prince

would you be interested in a small "bare bones minimum" tutorial on a few game designs?

Tookman
offline
Tookman
87 posts
Nomad

It's moving
but only left, the d isn't working, do you know why?

Tookman
offline
Tookman
87 posts
Nomad

I figured out the -= a minute ago, when I typed wait!, but the d won't work right, and yes I'd be interested.

I wish I knew you in person

weirdlike
offline
weirdlike
1,299 posts
Prince

skimming back the last few pages you only have A programmed you still haven't added the D press event

it needs to be both key pressed and key depressed

switch (e.keyCode)
{
	case Keyboard.A:
	{
		aDown = true;
		break;
	}
	case Keyboard.D:
	{
		dDown = true;
		break;
	}
}
Tookman
offline
Tookman
87 posts
Nomad

okay I did it
http://youtu.be/gWOieeI6Ogk

weirdlike
offline
weirdlike
1,299 posts
Prince

nice, I made a little thing on recording software HERE if you want to check that out

anywho... I am working on putting together a sample. It will be targeting both flash and flash develop, or pretty much any program that uses as3

it will include
- working with sprites
- player and AI (simple)
- collision
- timer and score

Does this sound simple and interesting enough to you?

Tookman
offline
Tookman
87 posts
Nomad

Check out my new player!;
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 ();
this.graphics.beginFill(0x000000, 1);
this.graphics.drawRect(this.x + 3, this.y + 7, 5, 2);
this.graphics.endFill ();
this.graphics.beginFill(0x000000, 1);
this.graphics.drawRect(this.x + 7, this.y + 2, 2, 2);
this.graphics.endFill ();
this.graphics.beginFill(0x000000, 1);
this.graphics.drawRect(this.x + 2, this.y + 2, 2, 2);
this.graphics.endFill ();
this.graphics.beginFill(0x000000, 1);
this.graphics.drawRect(this.x - 1, this.y - 1, 12, 2);
this.graphics.endFill ();
this.graphics.beginFill(0x000000, 1);
this.graphics.drawRect(this.x, this.y - 4, 10, 3);
this.graphics.endFill ();
}

}

}

Tookman
offline
Tookman
87 posts
Nomad

now I want to put a shark in, using the arrow keys, how do I do that?

Tookman
offline
Tookman
87 posts
Nomad

Okay, i almost have the shark in there, but there is one error on the line that states public function main void (the second time), what is wrong?;
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard
public class Main extends Sprite
{
private var aDown:Boolean = false;
private var dDown:Boolean = false;
private var sDown:Boolean = false;
private var wDown: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.KEY_DOWN, keysdown);
stage.addEventListener(KeyboardEvent.KEY_UP, keysup);
}
public function keys(e:Event):void
{
if (aDown == true)
char.x -= 10;
if (dDown == true)
char.x += 10;
if (sDown == true)
char.y += 10;
if (wDown == true)
char.y -= 10;
}
public function keysdown(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.A:
{
aDown = true;
break;
}
case Keyboard.D:
{
dDown = true;
break;
}
case Keyboard.S:
{
sDown = true;
break;
}
case Keyboard.W:
{
wDown = true;
break;
}
}
}
public function keysup(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.A:
{
aDown = false;
break;
}
case Keyboard.D:
{
dDown = false;
break;
}
case Keyboard.S:
{
sDown = false;
break;
}
case Keyboard.W:
{
wDown = false;
break;
}
}
}
private var gDown:Boolean = false;
private var jDown:Boolean = false;
private var hDown:Boolean = false;
private var yDown:Boolean = false;
private var par : shark;
public function main : void();
{
char = new player();
char.x = 300;
char.y = 100;
addChild(char);
stage.addEventListener(Event.ENTER_FRAME, keys);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keysdown);
stage.addEventListener(KeyboardEvent.KEY_UP, keysup);
}
public function keys(e:Event):void
{
if (gDown == true)
par.x -= 10;
if (jDown == true)
par.x += 10;
if (hDown == true)
par.y += 10;
if (yDown == true)
par.y -= 10;
}
public function keysdown(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.G:
{
gDown = true;
break;
}
case Keyboard.J:
{
jDown = true;
break;
}
case Keyboard.H:
{
hDown = true;
break;
}
case Keyboard.Y:
{
yDown = true;
break;
}
}
}
public function keysup(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.G:
{
gDown = false;
break;
}
case Keyboard.J:
{
jDown = false;
break;
}
case Keyboard.H:
{
hDown = false;
break;
}
case Keyboard.Y:
{
yDown = false;
break;
}
}
}
}

}

Tookman
offline
Tookman
87 posts
Nomad

oops, I copied that line wrong somehow, it's actually public function Main():void

weirdlike
offline
weirdlike
1,299 posts
Prince

if you are working with an img then there are a few ways to get it to appear on the screen. You can blit, copyPixel, or a simple addChild, just to name a few. The methods vary, but the general direction is embed > declare > addChild. Once you get the img to appear then the coding is exactly the same as the A and D buttons, but it will include a bit more to animate the shark.

EDIT: oop ninja'd I did not see your 2 posts there

Tookman
offline
Tookman
87 posts
Nomad

I'm not putting an image in.

Tookman
offline
Tookman
87 posts
Nomad

oops there were a few things I didn't put in, but it still won't work;
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard
public class Main extends Sprite
{
private var aDown:Boolean = false;
private var dDown:Boolean = false;
private var sDown:Boolean = false;
private var wDown: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.KEY_DOWN, keysdown);
stage.addEventListener(KeyboardEvent.KEY_UP, keysup);
}
public function keys(e:Event):void
{
if (aDown == true)
char.x -= 10;
if (dDown == true)
char.x += 10;
if (sDown == true)
char.y += 10;
if (wDown == true)
char.y -= 10;
}
public function keysdown(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.A:
{
aDown = true;
break;
}
case Keyboard.D:
{
dDown = true;
break;
}
case Keyboard.S:
{
sDown = true;
break;
}
case Keyboard.W:
{
wDown = true;
break;
}
}
}
public function keysup(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.A:
{
aDown = false;
break;
}
case Keyboard.D:
{
dDown = false;
break;
}
case Keyboard.S:
{
sDown = false;
break;
}
case Keyboard.W:
{
wDown = false;
break;
}
}
}
private var gDown:Boolean = false;
private var jDown:Boolean = false;
private var hDown:Boolean = false;
private var yDown:Boolean = false;
private var par : shark;
public function Main():void;
{
par = new shark();
par.x = 300;
par.y = 100;
addChild(char);
stage.addEventListener(Event.ENTER_FRAME, keys);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keysdown);
stage.addEventListener(KeyboardEvent.KEY_UP, keysup);
}
public function keys(e:Event):void
{
if (gDown == true)
par.x -= 10;
if (jDown == true)
par.x += 10;
if (hDown == true)
par.y += 10;
if (yDown == true)
par.y -= 10;
}
public function keysdown(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.G:
{
gDown = true;
break;
}
case Keyboard.J:
{
jDown = true;
break;
}
case Keyboard.H:
{
hDown = true;
break;
}
case Keyboard.Y:
{
yDown = true;
break;
}
}
}
public function keysup(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.G:
{
gDown = false;
break;
}
case Keyboard.J:
{
jDown = false;
break;
}
case Keyboard.H:
{
hDown = false;
break;
}
case Keyboard.Y:
{
yDown = false;
break;
}
}
}
}

}

Showing 46-60 of 128