ForumsProgramming ForumNew Programmer

128 45477
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
weirdlike
offline
weirdlike
1,299 posts
Prince

You can do it the same way you draw the player. If you have an img you want to use you will need to import it first.

blitting tutorial

Tookman
offline
Tookman
87 posts
Nomad

yeah I figured it out
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;

private var gDown:Boolean = false;
private var jDown:Boolean = false;
private var hDown:Boolean = false;
private var yDown:Boolean = false;
private var par : shark;

private var bar : Back;

public function Main():void
{

bar = new Back();
bar.x = 0;
bar.y = 0;
addChild(bar);

char = new player();
char.x = 500;
char.y = 300;
addChild(char);

par = new shark();
par.x = 600;
par.y = 400;
addChild(par);

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;

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.A:
{
aDown = true;
break;
}
case Keyboard.D:
{
dDown = true;
break;
}
case Keyboard.S:
{
sDown = true;
break;
}
case Keyboard.W:
{
wDown = true;
break;
}

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.A:
{
aDown = false;
break;
}
case Keyboard.D:
{
dDown = false;
break;
}
case Keyboard.S:
{
sDown = false;
break;
}
case Keyboard.W:
{
wDown = false;
break;
}

case Keyboard.G:
{
gDown = false;
break;
}
case Keyboard.J:
{
jDown = false;
break;
}

case Keyboard.H:
{
hDown = false;
break;
}
case Keyboard.Y:
{
yDown = false;
break;
}
}
}
}
}

Now how do I put objects in the game that spawn at random every time the old one is used that boost Bob's (the player's) speed +10?

Tookman
offline
Tookman
87 posts
Nomad

It just doesn't bold everything I want it to.

weirdlike
offline
weirdlike
1,299 posts
Prince

@Tookman

I specifically designed THIS tutorial at your request. Right now it is incomplete but it does answer these questions. Adding img's to visualize the characters and how to use the game loop to create and move units. Right now you are on the second PART, but I still recommend following from the start as it covers the very beginning steps. Examples for both flash and flashDevelop.

Tookman
offline
Tookman
87 posts
Nomad

I am very new to the language of flash does it have any words similar to or statements.

Tookman
offline
Tookman
87 posts
Nomad

um the tutorial confused me

weirdlike
offline
weirdlike
1,299 posts
Prince

I am very new to the language of flash does it have any words similar to or statements.

yes

um the tutorial confused me

Which part?

Tookman
offline
Tookman
87 posts
Nomad

um to be honest... all of it, all the flash I currently know is written in my program above so any words different from the ones in my program probably go right over my head. What is similar to "or" statements in flash?

weirdlike
offline
weirdlike
1,299 posts
Prince

Well... I find this strange as you have already done everything up to this point with your posted code in part 1 of the tutorial. Try spending more than 20 minutes reading.

Here is an example of statements, you have already been doing;

STATEMENTS

What is similar to "or" statements

"Or" is not a statement but an operator, it looks like this ||
HERE is a list of operators.

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

Ok weirdlike, I am not ready to use a blitting tool, I simply need to know whats wrong with this, when I get to the blitting tool step, I'll ask for some help... but first, what's wrong with this?

Tookman
offline
Tookman
87 posts
Nomad

sar = new Speed();
sar.x = -100 || 100 || 50 || 200 || 300 || 400
sar.y = 100 || 200 || 300 || 400
addChild(sar);

Tookman
offline
Tookman
87 posts
Nomad

The circle shows up, but its location isn't randomized

weirdlike
offline
weirdlike
1,299 posts
Prince

This code will randomly choose a number between 1 and 4.

then the randomized number will determine the exact placement, that you have chosen.

This is literally the second portion of PART 2 of the tutorial.

EDIT: if you scroll down to the bottom of each part, I have the source files there. You can download them and skim the code instead of reading the portions.

var randomX:int = Math.floor(Math.random()*4)+1;
Tookman
offline
Tookman
87 posts
Nomad

two questions:
1) is spawnblock a real word or do I have to define it as a variable?
2) Where do I put this new section of code to randomly spawn the speed boost?

weirdlike
offline
weirdlike
1,299 posts
Prince

This is a tutorial question?

is executing the function

The code will never execute unless there is a trigger or you specifically tell it to execute. In the purposes of the tutorial, the spawnBlock(); function is executed each frame.

NOTE: There should only be one EnterFrame loop. (Event.ENTER_FRAME, keys); is (Event.ENTER_FRAME, loop); in the tutorial. So either change the name and function or put all your looping code in the keys function.

spawnBlocks();
Showing 76-90 of 128