PDA

View Full Version : game borders



hitman1131
October 20th, 2004, 02:50 AM
hey guys im trying to make a little birds eye view game but i cant seem to get a bounary on the border to work to stop my character walking off the stage...

this is the codee i am using how can i put a boundary into it?

onClipEvent (enterFrame) {

if (Key.isDown(Key.UP)){
speed += 1;
gotoAndStop (2)
} else {
gotoAndStop (1)
speed = 0}

if (Key.isDown(Key.DOWN)) {
speed -= 0;
}
if (Math.abs(speed)>8) {
speed *= .8;
}
if (Key.isDown(Key.LEFT)) {
_rotation -= 10;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 10;
}

// This will make the car move
speed *= .98;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.wall.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.8;
}
}
<!-- / message -->

Dr Warm
October 20th, 2004, 03:46 AM
i think there's a problem with ur hittest, but i would do it like this instead:
//if 550 is the width of ur stage
if(this._x > 550){
speed *= -.8;
}
if(this._x < 0){
speed *= -.8;
}
if(this._y > 400){
speed *= -.8;
}
if(this._y < 0){
speed *= -.8;
}

hitman1131
October 20th, 2004, 04:08 AM
ok since im new to this and have only just modified a tutorials movement i dont know where to put this coded of yours...

i tryed it here...

speed *= .98;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if (!_root.move.hitTest(_x+x, _y+y, true)) {
if(this._x > 550){
speed *= -.8;
}
if(this._x < 0){
speed *= -.8;
}
if(this._y > 400){
speed *= -.8;
}
if(this._y < 0){
speed *= -.8;
}
} else {
speed *= -.6;
}
}

but it isnt working... the guy just stands in the middle and does nothing??

so where would i put this script?

if you need to see my file let me know and i will send it to you. Thanks in advance :D

Dr Warm
October 20th, 2004, 06:34 AM
no sorry i meant get rid of the hittest:
speed *= .98;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
if(this._x > 550){
speed *= -.8;
}
if(this._x < 0){
speed *= -.8;
}
if(this._y > 400){
speed *= -.8;
}
if(this._y < 0){
speed *= -.8;
}

if this doesn't work u might need to post a fla

hitman1131
October 20th, 2004, 07:55 AM
ok yeah it still didnt work :( he just wont walk now, he turns and stuff but not walk the file u'll be able to find here

http://home.ripway.com/2004-6/134081/walking_working.fla

Dr Warm
October 20th, 2004, 09:12 AM
i suggest u reread the tutorials u didn't have a wall movieclip or anyhting to hittest, i redid ur fla without the hittest (i don't use them and i can't remember how to!)

i suggest reading this tute (http://www.kirupaforum.com/forums/showthread.php?t=54066), tells u basics like this (i think)

Dr Warm

hitman1131
October 20th, 2004, 11:08 AM
yeah i trieed putting a wall mc there with the instance name of wall but my guy just seem to walk right through it. well thankyou very much for this help :D

2 quick things...
is it possible to not get the jump action he gets when colliding with the wall? can he just stop?

and

did u modify this is flash mx? cause i cant get it to open in flash 5 anymore. it say unnexpected file format. it wouldnt be a problem but i ahve to use flash 5 at skool.
so if there is a way i can get it to open in flash 5 again it would be kool.

again thx in advance. u really are helpfull thx :D

Dr Warm
October 21st, 2004, 03:50 AM
sorry i didn't realise u had flash 5, mmmmmmmmm u can save it in mx to flash 5, just go save as then click down the bottom to save in flash 5 format. Or did u want me to post it again?

also about that jump thing, it's the way that the code is set up, where i have this._x -= this._width/2 or whatever u can try changing this to a 1 ie:
this._x -= 1; then it won't jump so far. The problem is if u get it to stop, then how do u make it start again?

Another cool effect is just to loop him to the other side, so have
if(this._x > 550){
this._x = 0;
}
if(this._x < 0){
this._x = 550;
}
if(this._y > 400){
this._y = 0;
}
if(this._y < 0){
this._y = 400;
}

but u might not want this

hitman1131
October 21st, 2004, 06:13 AM
nah nah its kewl i got flash mx as well so i have changed the file... thx for ur help m8. :D

so i tried to put this in

if(this._x > 0){
_x += x;
_y += y;
} else {
_x += this._width;
speed *= 1;(this line)

and all my guy seems to do is hit the wall at a faster speed...
so there is no way to stop this?


just wondering isnt there a simple function where u could just say that it cant pass through a MC? cause it seems alot simpler...

Dr Warm
October 21st, 2004, 09:35 AM
just wondering isnt there a simple function where u could just say that it cant pass through a MC? cause it seems alot simpler... yeah there probably is, i'm just not aware of it for rotational games, umm but when u say can't pass through an object, there's two ways u can do it (i think):

1st: either not make the person be able to walk any further to that side, so has to pick reverse direction (i think u need trig for a rotational based game, don't quote me though :D)

2nd: 'bump' him away from the wall, ie what i did before

You can't just make him stop, cos how do u start? (i guess this is sort of like method 2)

Sorry i can't be of more help

hitman1131
October 21st, 2004, 11:09 AM
its quite alright Dr Warm u have been a great help thx so much.

about this...

1st: either not make the person be able to walk any further to that side, so has to pick reverse direction (i think u need trig for a rotational based game, don't quote me though )

how would i do this to give it a try and see if i like it?

Dr Warm
October 22nd, 2004, 07:01 AM
how would i do this to give it a try and see if i like it? i don't think i'll be able to do it based on what u've got (that's just not the way i code things), but i'll try and make one diffently now that it's the weekend, yay!

Dr Warm
October 23rd, 2004, 09:25 AM
You could have told me u copied the code word for word, from a certain overheadracing.fla, cos i didn't think i could do it, then i open it and it clicks where i'd seen that code from before, ok here it is with a wall, i also made it so it moves sort of more like a person

tblank99
November 8th, 2004, 10:30 AM
I have the same problem with my game, except i want my "man" to move in 8 directions, not to rotate like your guy but i still want the border effect.

here are the AS that im currently using

onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (key.isdown(key.LEFT)) {
_x -= speed;
}
if (key.isdown(key.RIGHT)) {
_x += speed;
}
if (key.isdown(key.DOWN)) {
_y += speed;
}
if (key.isdown(key.UP)) {
_y -= speed;
}
}

tblank99
November 8th, 2004, 10:41 AM
here is a screenshot i took of the level, the guy on the bottom is suppost to walk up the screen to the top where the gate is, but with out the border he just walks over the walls and leaves the screen.

then when he gets past the gate, im trying to make it go to the next scene witch would be the next level.

Dr Warm
November 8th, 2004, 11:05 PM
but with out the border he just walks over the walls and leaves the screen. do you mean without the hitTest? cos you can use the same hitTest as hitman1131 but you'll need to change it depending on direction (cm stands for can-move and registration should be in the centre):


onClipEvent (load) {

speed = 5;
cmLeft = true;
cmRight = true;
cmUp = true;
cmDown = true;

}
onClipEvent (enterFrame) {

if (key.isdown(key.LEFT) && cmLeft) {

_x -= speed;

}
if (key.isdown(key.RIGHT) && cmRight) {

_x += speed;

}
if (key.isdown(key.DOWN) && cmDown) {

_y += speed;

}
if (key.isdown(key.UP) && cmUp) {

_y -= speed;

}
if(wall.hitTest(_x+_width/2, _y, true){
cmRight = false;
} else {
cmRight = true;
}
if(wall.hitTest(_x-_width/2, _y, true){
cmLeft = false;
} else {
cmLeft = true;
}
if(wall.hitTest(_x, _y+_width/2, true){
cmUp = false;
} else {
cmUp = true;
}
if(wall.hitTest(_x, _y-_width/2, true){
cmDown = false;
} else {
cmDown = true;
}

}
that should work by memory, don't know though cos i h8 hitTests!!!

BTW the code screwed up when i posted it for some reason! just copy/paste it into flash

tblank99
November 9th, 2004, 10:16 AM
I copy pasted it and well i didnt let me... there was syntax errors

this was in the output

Clipboard Actions: Line 32: ')' expected
if(wall.hitTest(_x+_width/2, _y, true){

Clipboard Actions: Line 37: ')' expected
if(wall.hitTest(_x-_width/2, _y, true){

Clipboard Actions: Line 42: ')' expected
if(wall.hitTest(_x, _y+_width/2, true){

Clipboard Actions: Line 47: ')' expected
if(wall.hitTest(_x, _y-_width/2, true){

i tried to attach the .fla file but it was too big so i put it in a zip file

icio
November 9th, 2004, 02:58 PM
i think it should be:

x = Math.sin(_rotation/(Math.PI/180))*speed;
y = Math.cos(_rotation/(Math.PI/180))*speed*-1;

not sure if that will solve your problem, but it's a bug !
hope this helps :thumb:

Dr Warm
November 9th, 2004, 06:06 PM
oh sorry i always do that, miss the end bracket:
if(wall.hitTest(_x+_width/2, _y, true)){ like that for those four

hey cyberathlete i can't see what you've put there!

tblank99
November 10th, 2004, 09:46 AM
ok with your AS the guy moves and everything, but how do i make it so that he cannot run through walls

for a test i made a "wall"and named it all "wall" but i dont know what AS to put on it or where to put them so that it recognizes it as a wall and he will stop when he runs into it

tblank99
November 12th, 2004, 10:01 AM
any ideas?

tblank99
November 19th, 2004, 10:00 AM
can anyone help me out here, i have to turn this project in and well i dont know how to do the hitTest to make the walls and the exit work..... so if possible help will be apreciated

Dr Warm
November 19th, 2004, 10:05 AM
Ok i'll have a look at it, i might post l8r tonite if i find it, but it's 1230 am now......

Dr Warm
November 19th, 2004, 10:32 AM
Ok done, though i probably shouldn't have, u didn't even try my code!

you can't hitTest against just a bitmap, how does flash know which parts are walls?!?!?

i made two new layers, and traced your walls on one of them, and the other one is exits to the next place (i called them hotspots).

it doesn't go to the next scene, i'm not quite sure how to fix this, my suggestion: DON'T USE SCENES!!! (sorry if i had to shout!)

i put all the code in the main timeline if your looking for it.........

oh yeah i only did it for the first scene, hopefully you can see what to do know!