|
|
Tile Based
Does anyone know of a good tutorial on making a tile based platform game in flash MX?
FlashKit > Flash Help > Flash MX
Posted on: 06-26-2002, 01:34 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Tile Based
If you want to create a tile based game, do you have to create the tiles seperate, or do you have to draw a map and cut it into pieces (btw: how do you do that?)
Tile Based Map
If you have a tile based map, you have to draw all the tiles seperate. But how do you do the buildings? You can't draw pieces of buildings? :s:s
Thx in advance
Tile Based, AS 2.0
Does anyone know of any good articles or tutorials on creating tile based games, written for acionscript 2? I have been through TonyPa's examples, but need something that uses more up to date code.
Tile Based
ANyone seen any tile based flash tutorials out there?
Tile Based Game
i've been trying to learn to create tile based games but I can't remeber how to create them if i cant understand the code used. I've tried learning from the outside of society tut. can someone try to explain the stuff in the loop in the builmap function to me?
Tile Based Game
I am developing a side scrolling tile based game, where I want the tiles of a background to be attached to the stage when it first enters the stage, and the minute it goes out of the stage, it should be removed.
However, the tiles are not getting attached at the location that I am specifying. It generally gets attached at a location further than the one I specify.
I am writing the code below. If somebody could tell me what is going wrong, please do so, as I am stuck on this code.
I am declaring an array which has the different tile numbers. There are 5 tiles to be shown at a time, thus I have mentioned the starting and the ending tile number.
[b]myArray = new Array (1,1,1,1,1,1,1,1,1,1,1,1,1,1);
startTile = 0;
endTile = 5;
currentTile = 0;[b]
I am now using this script to generate the 5 tiles on stage -
for(var x = startTile; x< endTile; x++){
holder.attachMovie("Tile" + myArray[x], "clip"+ x, x+1);
holder["clip"+x]._x = -10 + (x*(92-10));
holder["clip"+x]._y = 176;
var obj = myObj[x];
if(obj != 0){
holder.attachMovie(obj, obj + x, 100+x);
holder[obj + x]._x = holder["clip"+x]._x;
holder[obj + x]._y = holder["clip"+x]._y;
filledObj.push(obj+x);
}
}
Tile Based Game
I am developing a side scrolling tile based game, where I want the tiles of a background to be attached to the stage when it first enters the stage, and the minute it goes out of the stage, it should be removed.
However, the tiles are not getting attached at the location that I am specifying. It generally gets attached at a location further than the one I specify.
I am writing the code below. If somebody could tell me what is going wrong, please do so, as I am stuck on this code.
I am declaring an array which has the different tile numbers. There are 5 tiles to be shown at a time, thus I have mentioned the starting and the ending tile number.
[b]myArray = new Array (1,1,1,1,1,1,1,1,1,1,1,1,1,1);
startTile = 0;
endTile = 5;
currentTile = 0;[b]
I am now using this script to generate the 5 tiles on stage -
for(var x = startTile; x< endTile; x++){
holder.attachMovie("Tile" + myArray[x], "clip"+ x, x+1);
holder["clip"+x]._x = -10 + (x*(92-10));
holder["clip"+x]._y = 176;
var obj = myObj[x];
if(obj != 0){
holder.attachMovie(obj, obj + x, 100+x);
holder[obj + x]._x = holder["clip"+x]._x;
holder[obj + x]._y = holder["clip"+x]._y;
filledObj.push(obj+x);
}
}
Tile Based Game
I am developing a side scrolling tile based game, where I want the tiles of a background to be attached to the stage when it first enters the stage, and the minute it goes out of the stage, it should be removed.
However, the tiles are not getting attached at the location that I am specifying. It generally gets attached at a location further than the one I specify.
I am writing the code below. If somebody could tell me what is going wrong, please do so, as I am stuck on this code.
I am declaring an array which has the different tile numbers. There are 5 tiles to be shown at a time, thus I have mentioned the starting and the ending tile number.
myArray = new Array (1,1,1,1,1,1,1,1,1,1,1,1,1,1);
startTile = 0;
endTile = 5;
currentTile = 0;
I am now using this script to generate the 5 tiles on stage -
for(var x = startTile; x< endTile; x++){
this.attachMovie("Tile" + myArray[x], "clip"+ x, x+1);
this["clip"+x]._x = -10 + (x*(92-10));
this["clip"+x]._y = 176;
}
I am now checking for a certain distance to be covered. Once that is done, a new tile has to be added at the end of the last tile, and the first tile has to be removed -
if(tempDir > currentTile){
currentTile +=1;
startTile += 1;
endTile += 1;
this.attachMovie("Tile" + myArray[endTile-1], "clip"+ (endTile-1), endTile);
this["clip"+(endTile-1)]._x = (this["clip"+ endTile]._x + 92);
this["clip"+(endTile-1)]._y = 176;
removeMovieClip(this["clip"+(startTile - 1)]);
}
Please tell me why this code isn't working and what can be done to make it work.
Mariam Dholkawala
Tile Based Games
Does anyone here know of a site with a good tutorial on tile based games for Flash MX, not AS2.
Help Me With Tile Based Gamez Plz
Hi everyone, Im trying to learn how to make flash tile based games using macromedia flash mx 2004. Ive taken like 2 tutorials but they always say like copy and paste this or right that and they dont explain any of the action script then when u right or copy that it dosnt work wow! So if someone is patient enough to help me with this because i dont really know much of anything besides like variables, buttons, get property, set property i would be so grateful!! Maybe if you want add me to msn that would be awesome!! joeyknudson@hotmail.com
thanks alot
-Joey-
Tile Based Games.
Hi im currently trying to learn how to make tile based games but its not really working to well. Ive read tonypas and oos tutorials but I still cant really pick it up. If anyone is into tile based games and would feel like chatting with me please post a reply!! There are so many questions I could ask and if maybe someone wanted to msn with me that would be great!!
thanks
-Joey-
Tile Based Game Help
Hi,
I'm going after TonyPa's tutorial, but I got some problems with the wall-coll.
dirx = direction in _x (1 or -1 or 0)
upright = ┐ (upright corner)
downright = ┘ (downright corner)
p = the player
playerx = tile pos for the player in x
right = tile pos for the players right in x
tw = tile width = 20
Actionscript:
Code:
if (dirx == 1) {
// going right
if (upright and downright) {
// if the whole right side is not hitting a wall
p._x += 1;
//go right
} else {
//if right side hits a wall
// [here]
p._x -= ((playerx-right)*tw)+tw;
// [/here]
// PLACE THE PLAYER, HOW AM I GOING TO DO?!
}
}
Link works now!
DOWNLOAD FLA: http://uploadany.com/imagehost/out.php/i5557_tiles3.zip
Please help really fast, I really need this!
[F8] Tile-based Pathfinding
Hey, I've been wanting to make a tile-based "click-to-move" type of game, and it occurred to me that I will need a few thing:
A way to set up a simple tile-based world with multiple types of terrain (probably best if they are dynamically placed)
a way to recognize which tile you click and if it is "visitable" (able to walk on)
a pathfinding algorithm (A* or something?) to get around "unvisitable" tiles
and an explaination on how the codes or whatever that you give me work so that I may change them if I have to
Thanks!
~Zippy Dee
Ted Newman
Tile Based Games
m trying to learn how to use the tile system for making games and have come accross a problem i cant figure out.. when you move it stops moving when you hit a ladder cos all the tiles are in the same MC ive been working off this code
function buildMap (map) {
var mapWidth = map[0].length;
var mapHeight = map.length;
for (var i = 0; i < mapHeight; ++i) {
for (var j = 0; j < mapWidth; ++j) {
this.attachMovie("tile", "t_"+i+"_"+j, ++d);
this["t_"+i+"_"+j]._x = (j*tileW);
this["t_"+i+"_"+j]._y = (i*tileH);
this["t_"+i+"_"+j].gotoAndStop(map[i][j]+1);
}
}
}
and on the character it has this
// check for collisions
// left / right
if ( cMap[downY2][leftX] > 1 || cMap[upY2][leftX] > 1 ) {
xpos -= xspeed;
xspeed = 0;
updateEdges();
}
if ( cMap[downY2][rightX] > 0 || cMap[upY2][rightX] > 0 ) {
xpos -= xspeed;
xspeed = 0;
updateEdges();
}
// up / down
if ( cMap[upY][leftX] > 0 || cMap[upY][rightX] > 0 ) {
var roof = (upY * tileH)+(tileH*1.5)
ypos = roof-gravity;
yspeed = 0;
}
if ( cMap[downY][leftX] > 0 || cMap[downY][rightX] > 0 ) {
var ground = (downY * tileH)-(tileH/2);
ypos = ground+gravity;
yspeed = 0;
but im stuck here with how to tell it to move left or right if its not block 1 or 2 so if it is a ladder it will walk through it ??
anyone know these things?
[CS3] Tile Based Game Help.
I got this scorse:
http://www.tonypa.pri.ee/tbw/start.html
form that tutorial, i have edited to my needs BUT. i want to be able to click a tile, it goes to the next level, frame or scene w/e
yes i could do that. but its not so simple. i make the button etc, or even a button outside the game. it switches over to the new frame in the background but the game has paused and has carried over to the next frame.
i have tryed doing this with a new scene (yes its the right go to scene script)
but it just keeps appearing where i dont want it to.
so how could i stop this?
Also once i done this how can i copy All actionscript and stuff on the frame to the new one after?]
Tile-based Problems
I had to completly redo my code for my game because apparently there isn't a way to move the character based on tiles or distance with the way I was doing it before. Altering speed couldn't work, he always ended up overlapping tiles.
-but now that i've re-done it he starts out with the walking animation right away! and stands in one square no matter what i do. i've been altering code all day and nothing is working, he just keeps doing the same thing. i'm posting the code pertaining to the character's movement thru his tile-based environment.... if anyone has time to look through and explain to me what I've done wrong it would really help me out
thanks!
PHP Code:
function moveChar(ob) {
// is char in the center of tile
if ((ob.x-game.tileW/2)%game.tileW == 0 and (ob.y-game.tileH/2)%game.tileH == 0) {
// calculate the tile where chars center is
ob.xtile = Math.floor(ob.x/game.tileW);
ob.ytile = Math.floor(ob.y/game.tileH);
// choose direction
//function detectKeys() {
var ob = _root.char;
var keyPressed = false;
if (Key.isDown(Key.RIGHT)) {
keyPressed = _root.movechar(ob, 1, 0);
ob.clip
} else if (Key.isDown(Key.LEFT)) {
keyPressed = _root.movechar(ob, -1, 0);
} else if (Key.isDown(Key.UP)) {
keyPressed = _root.movechar(ob, 0, -1);
} else if (Key.isDown(Key.DOWN)) {
keyPressed = _root.movechar(ob, 0, 1);
}
// walk animation
if (!keyPressed) {
ob.clip.char.gotoAndStop(1);
} else {
ob.clip.char.play();
}
}
// right
if (Key.isDown(Key.RIGHT)+(ob.xtile+1).walkable) {
ob.dirx = 1;
ob.diry = 0;
// left
} else if (Key.isDown(Key.LEFT)+(ob.xtile-1).walkable) {
ob.dirx = -1;
ob.diry = 0;
// up
} else if (Key.isDown(Key.UP)+"_"+ob.xtile.walkable) {
ob.dirx = 0;
ob.diry = 1;
// down
} else if (Key.isDown(Key.DOWN)+"_"+ob.xtile.walkable) {
ob.dirx = 0;
ob.diry = -1;
// none
} else {
ob.moving = false;
return;
}
}
function getTarget() {
// character must be moving
if (game["t_"+game.ymouse+"_"+game.xmouse].walkable) {
// update target tile
game.targetx = game.xmouse;
game.targety = game.ymouse;
// get moving
char.moving = true;
} else {
char.moving = false;
}
}
Tile Based Game Help
I don't understand how to get this code working properly!
The collision detection works okay until you try and move whilst touching a wall.
Ive been using the tutorials on Outside of Society to help, but i can't figure out whats gone wrong
heres the file -->
http://www.freewebs.com/firesuite/Flash/NewMove.swf
and heres the code -->
Code:
stop();
map = [[[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1]],
[[1,1],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[1,1]],
[[1,1],[0,0],[0,0],[1,1],[0,0],[0,0],[0,0],[0,0],[0,0],[1,1]],
[[1,1],[0,0],[0,0],[1,1],[0,0,"start"],[0,0],[0,0],[0,0],[0,0],[1,1]],
[[1,1],[0,0],[0,0],[4,0,"left"],[0,0],[0,0],[0,0],[0,0],[0,0],[1,1]],
[[1,1],[0,0],[0,0],[1,1],[1,1],[1,1],[1,1],[1,1],[2,0,"up"],[1,1]],
[[1,1],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[1,1],[2,0,"up"],[1,1]],
[[1,1],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[1,1],[2,0,"up"],[1,1]],
[[1,1],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[1,1]],
[[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1]]];
speed = 5;
skid = 10;
xpos = 10;
ypos = 10;
gox = 10;
goy = 10;
grav = 1;
charplace = false;
mw = Map.length;
mh = Map[0].length;
TileArray = new Array;
_root.createEmptyMovieClip("Holder",d++);
holder._x = xpos;
holder._y = ypos;
for (r=0; r<mh; r++) {
for (c=0; c<mw; c++) {
holder.attachMovie("tile","tile"+r+","+c,d++);
holder["tile"+r+","+c]._x = 20*c;
holder["tile"+r+","+c]._y = r*20;
holder["tile"+r+","+c].gotoAndStop((map[r][c][0])+1);
if (charplace==false) {
if ((map[r][c][2])=="start") {
charplace = true;
placex = c;
placey = r;
}
}
}
}
_root.attachMovie("char","char",d++);
char._x = (placex*20)+10;
char._y = (placey*20)+10;
_root.onEnterFrame = function() {
l = Math.floor((char._x-11)/20);
r = Math.floor((char._x+11)/20);
u = Math.floor((char._y-11)/20);
d = Math.floor((char._y+11)/20);
cy = Math.floor((char._y)/20);
ul = map[u][l][1];
ur = map[u][r][1];
dr = map[d][r][1];
dl = map[d][l][1];
if (dir=="up") {
if (ur==0) {
if (ul==0) {
char._y = char._y-speed+1;
}
} else {
char._y = cy+29;
}
} else if (dir=="right") {
if (dr==0) {
if (ur==0) {
char._x = char._x+speed;
}
}
} else if (dir=="down") {
if (dr==0) {
if (dl==0) {
char._y = char._y+speed;
}
}
} else if (dir=="left") {
if (dl==0) {
if (ul==0) {
char._x = char._x-speed;
}
}
}
if (Key.isDown(Key.UP)) {
dir = "up";
} else if (Key.isDown(Key.RIGHT)) {
dir = "right";
} else if (Key.isDown(Key.DOWN)) {
dir = "down";
} else if (Key.isDown(Key.LEFT)) {
dir = "left";
} else {
dir = null;
}
};
Thanks for any help...
oli
Tile Based Map Scroll
Hey , Well im trying to make a mario world like game which i recently started to make using a tutorial example .fla . im pretty new at flash game programming so im stuck in trying to make the map scroll. Pretty much i just want the map to scroll so that the player is always centered until it reaches the end or the begining of the map where at the end there will be a door that takes you to the next map. I would like to make it so that it only scrolls left and right as i wont be building any high obstacles in the game. Now the thing is i have tried tutorials like http://www.tonypa.pri.ee/tbw/tut14.html but once i add the scripts it looses its jump physics and stuff and the character moves up and down tiles instead of jumping and coming back down.
^ lol i know its confusing i got lost writing it myself but anyways if you know what im talking about please help =( ... ummm i atached what ive got so far of the game in case you wanna take a look at it and stuff... in the game , iv got the map( the first map, which is the one im working on for now) to be like 21 tiles wide and 10 tiles high, but i i would like for only 15 tiles in width to be displayed and the rest of the map will be shown as the character moves forward
ps: im not using actionscript 2
Xml Tile-based Game Map
hullo, all
this is a game map stored in an array inside flash file, but the problem is I wanna use an external xml file to store the map data. is there anyway to do it? I tried ask people at acitonscript room, but dont have any luck.
so...pls help!
thanks a lot. :)
Attach Code
fscommand("allowscale", false);
fscommand("allowscale", false);
// our map is 2-dimensional array
myMap = [[1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1]];
// declare game object that holds info
game = {tileW:30, tileH:30};
// walkable tile
game.Tile0 = function () { };
game.Tile0.prototype.walkable = true;
game.Tile0.prototype.frame = 1;
// wall tile
game.Tile1 = function () { };
game.Tile1.prototype.walkable = false;
game.Tile1.prototype.frame = 2;
// building the world
function buildMap(map) {
// attach empty mc to hold all the tiles and char
_root.attachMovie("empty", "tiles", ++d);
// declare clip in the game object
game.clip = _root.tiles;
// get map dimensions
var mapWidth = map[0].length;
var mapHeight = map.length;
// loop to place tiles on stage
for (var i = 0; i<mapHeight; ++i) {
for (var j = 0; j<mapWidth; ++j) {
// name of new tile
var name = "t_"+i+"_"+j;
// make new tile object in the game
game[name] = new game["Tile"+map[i][j]]();
// attach tile mc and place it
game.clip.attachMovie("tile", name, i*100+j*2);
game.clip[name]._x = (j*game.tileW);
game.clip[name]._y = (i*game.tileH);
// send tile mc to correct frame
game.clip[name].gotoAndStop(game[name].frame);
}
}
}
// make the map
buildMap(myMap);
stop();
[mx] - Tile Based Games Help
hi,
i'm fiddling about with tile based games at the moment and am working from the super good tonypa tutorials. i'd like to change the source code a bit so that i can play about with placing items onto the tile grid dynamically but need some help!
tile_dev2.fla
i've linked to the source file and would basically like some help to change a value in the map array so that it change the graphic displayed on the screen using a button or keypress maybe? i have a detectKey function working on the stage that is used to control the movement of the little birdy character i made. also maybe a function the change the character displayed on the screen (there are four of the little guys
thanks you guys are totally ace.
Tile Based Game: AS2.0
Hey guys,
Thank you for looking in. I'm actually trying to start again doing flash as AS has really caught my attention lately, I'm learning AS 2.0 at the moment (no money to buy CS3 to learn AS 3.0). So I really wanted to create a board game and I found this tutorial here in the forums (forgot the link tho), so it basically lead me to this site link and this site...now im having problems implementing them in AS 2.0... ive tried and looked in the forums and google, but i can't find an article/discussion that can help me understand how to implement the codes in AS 2.0..
Can someone please help...
Thank you!
G
Tile-based Problem
I'm having a big problem with my tile-based game. I create tiles based on a 2 dimensional array. Each tile is a Movie Clip, created using attachMovie. The problem is that when there are many of these tiles, the game lags, because so many properties must be stored for each MC. Is there a better method for creating "tiles" than attachMovie, or a way to free the memory used for each one?
PS. First post!
[mx] - Tile Based Games Help
hi,
i'm fiddling about with tile based games at the moment and am working from the super good tonypa tutorials. i'd like to change the source code a bit so that i can play about with placing items onto the tile grid dynamically but need some help!
tile_dev2.fla
i've linked to the source file and would basically like some help to change a value in the map array so that it change the graphic displayed on the screen using a button or keypress maybe? i have a detectKey function working on the stage that is used to control the movement of the little birdy character i made. also maybe a function the change the character displayed on the screen (there are four of the little guys
thanks you guys are totally ace.
Xml Tile-based Game Map
hullo, all
this is a game map stored in an array inside flash file, but the problem is I wanna use an external xml file to store the map data. is there anyway to do it?
pls help!
thanks a lot.
ActionScript Code:
fscommand("allowscale", false);
fscommand("allowscale", false);
// our map is 2-dimensional array
myMap = [[1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1]];
// declare game object that holds info
game = {tileW:30, tileH:30};
// walkable tile
game.Tile0 = function () { };
game.Tile0.prototype.walkable = true;
game.Tile0.prototype.frame = 1;
// wall tile
game.Tile1 = function () { };
game.Tile1.prototype.walkable = false;
game.Tile1.prototype.frame = 2;
// building the world
function buildMap(map) {
// attach empty mc to hold all the tiles and char
_root.attachMovie("empty", "tiles", ++d);
// declare clip in the game object
game.clip = _root.tiles;
// get map dimensions
var mapWidth = map[0].length;
var mapHeight = map.length;
// loop to place tiles on stage
for (var i = 0; i<mapHeight; ++i) {
for (var j = 0; j<mapWidth; ++j) {
// name of new tile
var name = "t_"+i+"_"+j;
// make new tile object in the game
game[name] = new game["Tile"+map[i][j]]();
// attach tile mc and place it
game.clip.attachMovie("tile", name, i*100+j*2);
game.clip[name]._x = (j*game.tileW);
game.clip[name]._y = (i*game.tileH);
// send tile mc to correct frame
game.clip[name].gotoAndStop(game[name].frame);
}
}
}
// make the map
buildMap(myMap);
stop();
TILE BASED SCROLLING - Resources Please?
I'm looking into creating a tile based games engine however I would like to look at other engines for ideas and tips. If anyone know of any tile based engines on the net or are currently developing themselves please could you let me know!
Thank you
Gary
Tile Based Game Help (Flash 5)
Does anyone out there know any good tile based game sample files or anything like that, i did have a good example but it ****s up whenever i add in the blocks, it is fine the guy walks on it, but when i make a new frame, or new scene whatever, the character bumps into the blocks that were originaly on the prevoius frame, but they are invisibly there on the next, ahhh to confusing, by!
Collision Detection In Tile-based
Is there a simple way to do collision detection on a tile-based map like:
Code:
if (this.hitTest(map1[0][1])) {
this._alpha -= 20;
}
I know that won't work, but something along those lines. Thanks
Best Way Of Scrolling In Tile-based-games?
im making a tile-based-game, in AS2.
and im looking for the fastest and best way of scrolling and stuff.
on the oos.moxiecode.com site it says that he's not interily sure of which way of scrolling is the best, and also that they're good in different ways.
though he uses the way of just attaching the tiles that are in the visible area, then when they go outside the screen, he removes them, and attaches new tile-objects at the other side.
tonypa does it differently, he also just shows the tiles in the visible area, but instead of removing and attaching new ones, he moves the old ones and change their frames to the correct ones.
also, on the oos.moxiecode.com site he mentions something about object oriented scripting being the fastest. but whats that? =S
all i want to do is to get my game run as smooth and possible, and not too slow on slow computers.
thanks in advance.
Trajectory In Tile-based Game
ei peeps!
currently making a tile-based game, with a 45 degree angle perspective. I have some enemy movieclips on the board and i want them to throw a granade at any target square on the grid. Of course, granades have to follow a trajectory from start to finish. I know that i can use Math.sin and Math.cos to calculate a path, but i'm stump in trying to figure out, how to calculate the trajectory so that it would hit a target square especially since i'm viewing the grid at an angle.
any help would be very mush appreciated.
Newbie Tile Based Game
i wana make a tile based game but dont have the skills to do some of it... i need some 1 to plz help me edit the attached file and make it do:
make it when u jump u continue to fly up until the jump button is let go
set up a new door prototype so that when the hero moves into it u go and stop on a differnt frame
(PS: the attached file is one from tonypa's site)
Tile Based World Movement
OK I got the map working..
got to making multiple mcs and attaching them correctly
selecting them
deselecting them
deleting them..
and moving them, well not all the way...
So what I have so far here is:This beta/alpha/not done yet thing..
If you check it out you'll see that it can move after being selected
but.. it wont move if there's a tree in front of the soldier(pathetic drawing .. I know just working on the engine..)
and another thing is that some times it just go crazy and leave the stage..
and one last thing that i might be able to fix is that it can move to the same tile where there's another soldier...
well I need some help in the moving algorithm(witch is not an algorithm now.. but still )
and.. why the thing is going crazy
when anyone here is interested in helping ill post the code or the fla or both :P
ok well hoping for a responce
Urgent Tile Based Map Scrolling
let's trry this on flashkit :P on actionscript.org i didnt get much replys
hi all,
please help me on this one, any suggestions are welcome.
i'm busy with making a map scroll thing that can scroll left and right (with tiles).
i've scrolled all over the net. finally fouund the wonderfull tutorial: http://oos.moxiecode.com/tut_04/index.html
[edit] lol i mean i've surfed all over the net [/edit]
the ****ty thing about this tutorial is, it can only scroll left and right.. i've been busy a few days with making it scroll up and down also..
these are the 2 codes for left and down:
Code:
// right
if ( dir == "right" && j <= mapW ) {
this.scrClip._x -= scrSpeed;
majorX += scrSpeed;
if ( majorX >= tileW ) {
for ( var lasti=(i-visAreaY); lasti<(i); ++lasti ) {
for ( var lastj=j; lastj<(j+1); ++lastj ) {
this.scrClip.attachMovie("tile", "t_"+lasti+"_"+lastj, ++d);
this.scrClip["t_"+lasti+"_"+lastj]._x = lastj*tileW;
this.scrClip["t_"+lasti+"_"+lastj]._y = lasti*tileH;
this.scrClip["t_"+lasti+"_"+lastj].gotoAndStop ( map1[lasti][lastj][0] );
removeMovieClip ( this.scrClip["t_"+lasti+"_"+(lastj-visAreaX-1)] );
}
}
++j;
majorX -= tileW;
}
}
// left
if ( dir == "left" && (j-visAreaX) > 0 ) {
this.scrClip._x += scrSpeed;
majorX -= scrSpeed;
if ( majorX <= 0 ) {
--j;
for ( var lasti=(i-visAreaY); lasti<(i); ++lasti ) {
for ( var lastj=(j-visAreaX-1); lastj<(j-visAreaX); ++lastj ) {
this.scrClip.attachMovie("tile", "t_"+lasti+"_"+lastj, ++d);
this.scrClip["t_"+lasti+"_"+lastj]._x = lastj*tileW;
this.scrClip["t_"+lasti+"_"+lastj]._y = lasti*tileH;
this.scrClip["t_"+lasti+"_"+lastj].gotoAndStop ( map1[lasti][lastj][0] );
removeMovieClip ( this.scrClip["t_"+lasti+"_"+(lastj+visAreaX+1)] );
}
}
majorX += tileW;
}
}
now i need the up and down.. but i just keep doing things wrong..
i've tried to contact the owner of the tutorial website, but he stopped with flash as far i know (or he don't check his mail for a long time)..
i've searched google, found guys who have had the same "problem" but nobody appears to have the answer
i'm deseparet.. please help me
Tile Based - Destroy Tiles
Hello, name's Matt, new to FlashKit.
I've been using flash for some time now, so I'm nothing short of cluey when it comes to making applications and such, although the game scene is never something iv'e tapped into.
Been following the wonderful tutorials by Sir.Tonypa, and Klas (OOS), and have a general understanding of how it's all working.
Im making a small Pac-man type of game, where as I can shoot, and blow holes through walls, as can the enemy.
Ive managed to get some cool AI working, and for them to shoot and attack me as I do the enemy. although my question is about how do I go about changing tile states to walkable/non-walkable once been shot... for a while I figured i could throw in a 'non-moving' enemy, that when i shoot, it dies and becomes a walkable area, although this didn't seem to work as planned.
I guess I'm just looking for some guidance, not so much as source and examples (keen to try this without ripping anyones code). So if anyone knows of links to similar posts with answers, or anything that may be of assistance, it would be mucho appreciated.
Mind you, I have been searching, for a few days now, and nothing has shown up with what I'm after.
Cheers guys, lookin forward to a favorable responce
--
Matt
Tile-based Maze Game Help
Hey everyone,
Just joined and was looking for some help with this game i'm making but it is like looking for a needle in a haystack in these threads.
So here's the story:
I am in the middle of making a maze game based on tiles where the user has to guide the character through the maze and find the exit. Pretty basic i know, but i thought i would try and figure out the solution my way rather than just use a loop to initiate the grid (thinking back now, that was probably the best way to do it but i've started it now and want to finish it).
First i created a square, made it into a movie clip and named it cell. I then copied instances of this cell onto the stage and made a 8x10 grid. I then gave each cell a different instance name (like chess with A1, B2, etc).
Next i made a new layer and created my maze over the top of these cells. In my mind i was thinking of making a reference to these cells so that i would know where the wall was and could then make coding in order to restrict movement (i.e if there was a wall to the left, i would make a variable within that cell and call it somethin like "L1" and then later use a function to determine where this wall was and restrict movement to the left). So i proceeded to do this which was all good.
But when it came to making the final coding it didn't all go to plan.
I was having great difficuly in coming up with a method to obtain which cell the character was currently in (thought about using the hitTest method but that wasn't really suitable). So in the end i decided to keep track of the current cell by making 2 variables to store the current x and y position and then incrementing/decrementing that number whenever the character is moved.
I'll post the coding up, but the main problem was that i couldn't obtain the variable that was within that cell (to see where the wall was located). I had a reference stored(using the above method) which was exactly the same as the instance name and i tried to convert this reference to the actual movie clip but was unsuccessful in doing so.
Any help would be most helpful
Hit Test Problems Tile Based Only?
ok, I am working on this game looking on how my guy can finallly stop going though the floor and from forums they are saying that i must do it throught tile base is this the only way, if not can you please help me with this Here is some sample code that I have tried but so far has not worked.
onClipEvent(load){
moveSpeed=10;
gravity=7
}
onClipEvent (enterFrame) {if (Key.isDown(Key.SPACE)) {
laserCounter++;
_root.laser.duplicateMovieClip( "laser"+laserCounter, laserCounter );
_root["laser"+laserCounter]._visible=true;
}
this._y+=gravity;
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
}
else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
y;
if (Key.isDown(Key.DOWN)) {
this._y+=moveSpeed;
} else if (Key.isDown(Key.UP)) {
this._y-=moveSpeed;
}
if (hittest(run)==true) {
_y=_y-10;}
}
Tile Based Collision Detection
I am following Tonypa's Tile Based Tutorials and I have to say, they are great. He covers everything needed, except for one thing I am troubled on - Refering to Tutorial 9, http://www.tonypa.pri.ee/tbw/tut09.html, Stupid Enemy, instead of an enemy I want to make this a NPC who walks around in a village. So what do I do to make it so that I, or the char, doesn't walk right over the enemy/NPC? I am trying to develop an RPG, and it would look silly to have the character walk on top of the NPC. Can someone provided a snippet on how to make a collision detection with the NPC and not walk on top/under the NPC?
One last favor to ask: What if I want to talk to the NPC if I am within a half tile? Would anyone be willing to share info on how this as well?
Thanks a bunch in advance
[JavaScript] Tile Based Platformer
a little something i cooked up during the absence of Flash that i am currently suffering to.
FIREFOX HTML:
Code:
<html>
<head>
<title>JavaScript Tilebased Scripting</title>
<style type="text/css">
div {
font-family: verdana;
font-size: 10px;
text-align: center;
}
.wall {
background-color: #EFEFEF;
border-color: #CCCCCC;
border-width: 1px;
border-style: solid;
position: absolute;
height: 19px;
width: 19px;
}
.character {
background-color: #DD9999;/*#9999DD*/;
border-color: #000000;
border-width: 1px;
border-style: solid;
position: absolute;
height: 19px;
width: 19px;
}
#controller {
background-color: #EFEFEF;
border-color: #CCCCCC;
border-width: 1px;
border-style: solid;
font-family: verdana;
font-size: 10px;
text-align: center;
}
</style>
<script language="JavaScript">
var objCount = 0;
startTile = {x: 1, y: 9};
var map = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
];
xOffset = 40;
yOffset = 40;
tileSize = 20; //if changing, remember to update the css too.
function makeObj(type, x, y) {
// <div class="type" style="top: xpx; left: ypx" />
if (type=="wall") {
name = type+"_"+x+"_"+y;
} else {
name = type+"_"+objCount;
}
writeThis = "<div id='"+name+"' class='"+type+"' style='left: "+Number(x*tileSize+xOffset)+"px; top: "+Number(y*tileSize+xOffset)+"px'>"+objCount+"</div>";
objCount++;
document.write(writeThis);
eval(name).x = x;
eval(name).y = y;
return eval(name);
}
function assessMap() {
for (y=0; y<map.length; y++) {
for (x=0; x<map[0].length; x++) {
if (map[y][x] == 1) {
makeObj("wall", x, y);
}
}
}
}
assessMap();
var mainChar = makeObj("character", startTile.x, startTile.y); //mainChar now acts as a reference to the div object for the character.
testDirections(mainChar);
function assessKeysDown(evt) {
key = evt.keyCode;
if (key == 37) {
keyLeft = true;
}
if (key == 39) {
keyRight = true;
}
if (key == 38) {
keyUp = true;
}
}
function assessKeysUp(evt) {
key = evt.keyCode;
if (key == 37) {
keyLeft = false;
}
if (key == 39) {
keyRight = false;
}
if (key == 38) {
keyUp = false;
}
}
function testDirections(currObj) {
left = Number(String(currObj.style.left).substring(0, String(currObj.style.left).length-2));
top = Number(String(currObj.style.top).substring(0, String(currObj.style.top).length-2));
bottom = Math.floor((top+tileSize-1-yOffset)/tileSize);
top = Math.floor((top-yOffset)/tileSize);
right = Math.floor((left+tileSize-1-xOffset)/tileSize);
left = Math.floor((left-xOffset)/tileSize);
currObj.canUp = true;
currObj.canDown = true;
currObj.canLeft = true;
currObj.canRight = true;
if (map[top-1][left] == 1 || map[top-1][right] == 1) {
currObj.canUp = false;
currObj.maxTop = top*tileSize+yOffset;
}
if (map[bottom+1][left] == 1 || map[bottom+1][right] == 1) {
currObj.canDown = false;
currObj.maxBottom = bottom*tileSize+yOffset;
}
if (map[top][left-1] == 1 || map[bottom][left-1] == 1) {
currObj.canLeft = false;
currObj.maxLeft = left*tileSize+xOffset;
}
if (map[top][right+1] == 1 || map[bottom][right+1] == 1) {
currObj.canRight = false;
currObj.maxRight = right*tileSize+xOffset;
}
//document.title = "t: "+top+", b: "+bottom+", l: "+left+", r: "+right;
document.title = "Up: "+currObj.canUp+", Down: "+currObj.canDown+", Right: "+currObj.canRight+", Left: "+currObj.canLeft;
}
//the main controller loop:
keyUp = false;
keyLeft = false;
keyRight = false;
xSpeed = 0;
ySpeed = 0;
function loop() {
left = Number(String(mainChar.style.left).substring(0, String(mainChar.style.left).length-2));
top = Number(String(mainChar.style.top).substring(0, String(mainChar.style.top).length-2));
if (keyRight) {
xSpeed += xSpeed < 5 ? 1 : 0;
} else if (keyLeft) {
xSpeed -= xSpeed > -5 ? 1 : 0;
} else {
xSpeed -= xSpeed != 0 ? xSpeed/Math.abs(xSpeed) : 0;
}
left += xSpeed;
//test that the object is still within bounds
if (!mainChar.canLeft && left < mainChar.maxLeft) {
left = mainChar.maxLeft;
}
if (!mainChar.canRight && left > mainChar.maxRight) {
left = mainChar.maxRight;
}
if (keyUp && !mainChar.canDown) {
ySpeed = -10;
}
ySpeed += ySpeed <= 19 ? 1 : 0; //gravitational effect
if (!mainChar.canDown && top + ySpeed > mainChar.maxBottom) {
ySpeed = 0;
top = mainChar.maxBottom;
}
if (!mainChar.canUp && top + ySpeed < mainChar.maxTop) {
ySpeed = 0;
top = mainChar.maxTop;
}
top += ySpeed;
mainChar.style.left = left;
mainChar.style.top = top;
testDirections(mainChar);
//loop again:
setTimeout("loop()", 100);
}
setTimeout("loop()", 100);
</script>
</head>
<body onKeyDown="assessKeysDown(event)" onKeyUp="assessKeysUp(event)" >
</body>
</html>
Library For Tile-based Games
ActionScript Code:
function drawMap(map) { mapH = map.length; mapW = map[0].length; num = 0; attachMovie("tile", "tile", mapH * mapW); tileW = tile._width; tileH = tile._height; for (i = 0; i < mapW; i++) { for (j = 0; j < mapH; j++) { tile.duplicateMovieClip("tile" + num, num); t = this["tile" + num]; t.gotoAndStop(map[j][i]); //trace(map[i][j]); t._width = tileW; t._height = tileH; t._x = tileW * i; t._y = tileH * j; num++; //trace(num); } } tile.removeMovieClip();}function checkTile(x, y) { count = mapH*mapW; for (k=0; k<count; k++) { name = _root["tile"+k]; if (name.hitTest(x,y)) { return k; } }}MovieClip.prototype.nextTile = function() { if (this._currentframe == this._totalframes) this.gotoAndStop(1); else this.nextFrame();};
It requires a movieclip in the library with a linkage name of tile. Inside this movieclip starting a frame 1, on each frame, is a tile (say grass on frame 1, water on frame 2, etc.).
Drawmap, obviously, draw's the map. It's paramater (map) is a 2d array that contains all the tiles needed. It also uses the only movieclip needed (at the moment!) which contains all our tiles.
Checktile, takes in two coordinates (x, y) and runs through all the tiles to see which one (if any) the coords are on. It returns the number of the tile. Drawmap labels each tile tile0, tile1, tile2, tile3, etc. and checktile returns the number in that name.
nextTile, is a prototype that is called on the tile movieclip, it's basically an extended nextFrame() as it checks to see if it's on the last frame and if so start again. This function has a use in a map editor.
An example using this and checkTile is, again, in a map editor, to change the selected tile to it's next state.
ActionScript Code:
_root["tile"+checkTile(_xmouse, _ymouse)].nextTile();
2d Array, is arrays inside arrays, used for building tile-worlds. Here is an example for a 10x10 world:
ActionScript Code:
var map:Array = [ [3, 2, 2, 2, 2, 2, 2, 3, 1, 1], [3, 3, 3, 2, 2, 2, 3, 3, 1, 1], [1, 1, 3, 3, 3, 3, 3, 1, 1, 1], [1, 1, 1, 1, 1, 1, 4, 4, 4, 4], [1, 4, 4, 4, 4, 4, 4, 4, 4, 4], [4, 4, 4, 4, 2, 2, 4, 4, 4, 4], [4, 4, 4, 4, 2, 2, 4, 4, 4, 4], [4, 4, 4, 4, 4, 2, 4, 4, 4, 4], [1, 1, 1, 4, 4, 2, 4, 4, 1, 1], [1, 1, 1, 1, 3, 2, 3, 1, 1, 1] ];
***
Very small at the moment, but it'll grow as I continue with my latest project. It's the first time I've played with tiles.
Unnatural - Tile Based Game
Hey!
In the summer (end of June+) I am completly free and I think I would like to make this game I had in my mind for a long time now.
Using some of Tonypa's ideas and a lot of mine I think it would be possible for me to make a tile based game. It would include really nice graphics (not tile - to - tile graphics), good gameplay (jumping around, shooting, blood, maybe some physics) and a plotline (told by the charaters). I am 15 and I am aware that all this <^> sounds kinda naive and it is in someways, but please read on!
Technically I have already got the tile based collision and some of the shooting scripting. But I think I have learnt a lot more since i first started and could improve my script.
There are 3 things that worry me before I start:
- Animation combined with the realtime world (like the player) is going to be a ***** to do but I could incorporate it into the background even though this would make triggering the animations kinda tricky
- Sound I have no idea where I would get the voice acting from or explosion/shooting/death sounds
- OOP, I like don't REALLY know it. Stuff like prototypes and classes etc are beyond me, I guess I should learn this stuff?
(Most other things like AI I have ideas for but not actually put into practice)
And finally, how come no one has made a "proper" mini-game in flash. The closest thing I can think of is Madness Interactive (ownage of a game) but it is still quite simple as the player moves from kill zone to kill zone. Why has no one made these kind of games!? There must be someone who has. Its purley for ideas sake and the knowledge that it can be done. Seeing as most games have no plot and are very simple my task/idea seems a bit too hard maybe.
Thanks for the help (and reading!)
Dan
Porblem With Tile-based Game
Hello all, I'm working in actionscript 2 and I'm developing a tile based game. Before I can get to the issue, I'll describe the workflow.
The levels(screens) are arranged in 3 dimensional arrays
so level1=[[1,1,1],[2,2,2],[3,3,3],[4,4,4]];
The level would look like
111
222
333
444
(each number being an id for a tile)
the function genMap handles generating the map
there is one instance of each tile offstage that is a "pure" clip.
genMap moves each pure tile to the position according to it's position on the array, and then duplicates it, swaps its depth, and places it offstage. etc. etc. until the whole map is loaded.
when you switch maps, a clearMap is run that removes all of the nonpure tiles, and genMap is run again.
during play, you cannot run into walls so each move goes through a function called movePermit that checks each solid tile's position against your next move. This works fine except for some reason it tends to slow down after a while, until I move to another map and then it works at normal speed again. It seems to happen faster when there are more solids in the current level. I have a debug mode and I have checked to see which functions are running, but all functions run when they should. When you are standing still, no functions are running.
Would anybody know why it's happening?
Tile-based Scrolling - Slowdown
Hello,
I am programing a tile-based RPG game and I want the player's character to stay in the center of the screen while walking, scrolling the screen in the oposite direction instead of moving the char.
I'm an AS3 beginner and I didn't know that it would result in a great slowdown of the game, so first I tried just to move the whole world. Then I read about the scrollRect method but when I used it the speed didn't improve, even using cacheAsBitmap (it works only for a small scrolling area and I don't want my RPG to be gameBoy-sized). I tried some other things like moving each tile with a loop and even blocks of 50 tiles with 1ms intervals (that worked but looked strange). I even tried to copyPixel but I must be doing something wrong because it causes an ever greater slowdown. The problem is that I don't know how to copyPixel into a bitmap without creating a new BitmapData and then a new Bitmap. Right now each tile is a movieclip stopped in the corresponding frame with some properties I use for the pathfinding.
So now I don't know what to do and I need your help. I know there is some GAS scrolling method but I couldn't find how it works. There are some other advanced tricks out there but I don't understand them well, so I hope you could help me.
Any other methods would also be great. Anything that works for a scrolling screen at last, lets say, 600X500.
[JavaScript] Tile Based Platformer
a little something i cooked up during the absence of Flash that i am currently suffering to.
FIREFOX HTML:
Code:
<html>
<head>
<title>JavaScript Tilebased Scripting</title>
<style type="text/css">
div {
font-family: verdana;
font-size: 10px;
text-align: center;
}
.wall {
background-color: #EFEFEF;
border-color: #CCCCCC;
border-width: 1px;
border-style: solid;
position: absolute;
height: 19px;
width: 19px;
}
.character {
background-color: #DD9999;/*#9999DD*/;
border-color: #000000;
border-width: 1px;
border-style: solid;
position: absolute;
height: 19px;
width: 19px;
}
#controller {
background-color: #EFEFEF;
border-color: #CCCCCC;
border-width: 1px;
border-style: solid;
font-family: verdana;
font-size: 10px;
text-align: center;
}
</style>
<script language="JavaScript">
var objCount = 0;
startTile = {x: 1, y: 9};
var map = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
];
xOffset = 40;
yOffset = 40;
tileSize = 20; //if changing, remember to update the css too.
function makeObj(type, x, y) {
// <div class="type" style="top: xpx; left: ypx" />
if (type=="wall") {
name = type+"_"+x+"_"+y;
} else {
name = type+"_"+objCount;
}
writeThis = "<div id='"+name+"' class='"+type+"' style='left: "+Number(x*tileSize+xOffset)+"px; top: "+Number(y*tileSize+xOffset)+"px'>"+objCount+"</div>";
objCount++;
document.write(writeThis);
eval(name).x = x;
eval(name).y = y;
return eval(name);
}
function assessMap() {
for (y=0; y<map.length; y++) {
for (x=0; x<map[0].length; x++) {
if (map[y][x] == 1) {
makeObj("wall", x, y);
}
}
}
}
assessMap();
var mainChar = makeObj("character", startTile.x, startTile.y); //mainChar now acts as a reference to the div object for the character.
testDirections(mainChar);
function assessKeysDown(evt) {
key = evt.keyCode;
if (key == 37) {
keyLeft = true;
}
if (key == 39) {
keyRight = true;
}
if (key == 38) {
keyUp = true;
}
}
function assessKeysUp(evt) {
key = evt.keyCode;
if (key == 37) {
keyLeft = false;
}
if (key == 39) {
keyRight = false;
}
if (key == 38) {
keyUp = false;
}
}
function testDirections(currObj) {
left = Number(String(currObj.style.left).substring(0, String(currObj.style.left).length-2));
top = Number(String(currObj.style.top).substring(0, String(currObj.style.top).length-2));
bottom = Math.floor((top+tileSize-1-yOffset)/tileSize);
top = Math.floor((top-yOffset)/tileSize);
right = Math.floor((left+tileSize-1-xOffset)/tileSize);
left = Math.floor((left-xOffset)/tileSize);
currObj.canUp = true;
currObj.canDown = true;
currObj.canLeft = true;
currObj.canRight = true;
if (map[top-1][left] == 1 || map[top-1][right] == 1) {
currObj.canUp = false;
currObj.maxTop = top*tileSize+yOffset;
}
if (map[bottom+1][left] == 1 || map[bottom+1][right] == 1) {
currObj.canDown = false;
currObj.maxBottom = bottom*tileSize+yOffset;
}
if (map[top][left-1] == 1 || map[bottom][left-1] == 1) {
currObj.canLeft = false;
currObj.maxLeft = left*tileSize+xOffset;
}
if (map[top][right+1] == 1 || map[bottom][right+1] == 1) {
currObj.canRight = false;
currObj.maxRight = right*tileSize+xOffset;
}
//document.title = "t: "+top+", b: "+bottom+", l: "+left+", r: "+right;
document.title = "Up: "+currObj.canUp+", Down: "+currObj.canDown+", Right: "+currObj.canRight+", Left: "+currObj.canLeft;
}
//the main controller loop:
keyUp = false;
keyLeft = false;
keyRight = false;
xSpeed = 0;
ySpeed = 0;
function loop() {
left = Number(String(mainChar.style.left).substring(0, String(mainChar.style.left).length-2));
top = Number(String(mainChar.style.top).substring(0, String(mainChar.style.top).length-2));
if (keyRight) {
xSpeed += xSpeed < 5 ? 1 : 0;
} else if (keyLeft) {
xSpeed -= xSpeed > -5 ? 1 : 0;
} else {
xSpeed -= xSpeed != 0 ? xSpeed/Math.abs(xSpeed) : 0;
}
left += xSpeed;
//test that the object is still within bounds
if (!mainChar.canLeft && left < mainChar.maxLeft) {
left = mainChar.maxLeft;
}
if (!mainChar.canRight && left > mainChar.maxRight) {
left = mainChar.maxRight;
}
if (keyUp && !mainChar.canDown) {
ySpeed = -10;
}
ySpeed += ySpeed <= 19 ? 1 : 0; //gravitational effect
if (!mainChar.canDown && top + ySpeed > mainChar.maxBottom) {
ySpeed = 0;
top = mainChar.maxBottom;
}
if (!mainChar.canUp && top + ySpeed < mainChar.maxTop) {
ySpeed = 0;
top = mainChar.maxTop;
}
top += ySpeed;
mainChar.style.left = left;
mainChar.style.top = top;
testDirections(mainChar);
//loop again:
setTimeout("loop()", 100);
}
setTimeout("loop()", 100);
</script>
</head>
<body onKeyDown="assessKeysDown(event)" onKeyUp="assessKeysUp(event)" >
</body>
</html>
Tile Based Stopping... Help Needed
Hey,
Im working on a tile based game in flash with the help of some online tutorials and guesswork. So far its going well aside from that my character seems too go partially inside the ground and in walls whenever i fall onto the ground or run into walls... anyone help me fix this? (ps ignore some of the obvious and pointess comments i put them there just to remind me of things i get confused by)
Code:
map_1 = [
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1]];
tile_size = 20;
current_map = 1;
ground_acceleration = 1;
ground_friction = 0.5;
ice_acceleration = 0.1;
ice_friction = 0.90;
max_speed = 3
y_max_speed = 10;
xspeed = 0;
herox = 1;
heroy = 0;
hero = {};
// build world
function make_world(map) {
// create empty movie clip
_root.createEmptyMovieClip("level_clip", 1);
// .length defines the number of variables in the map array
var mapWidth = map[0].length;
var mapHeight = map.length;
for (var i = 0; i<mapHeight; ++i) {
for (var j = 0; j<mapWidth; ++j) {
var name = "t_"+i+"_"+j;
level_clip.attachMovie("tile", name, _root.level_clip.getNextHighestDepth());
level_clip[name]._x = (j*tile_size);
level_clip[name]._y = (i*tile_size);
level_clip[name].gotoAndStop([map[i][j]+1]);
}
}
//calculate starting position
hero.x = herox*tile_size;
hero.y = heroy*tile_size;
//place hero mc
level_clip.attachMovie("hero", "hero", 10000, {_x:hero.x, _y:hero.y});
}
_root.onEnterFrame = function() {
ground_under_feet();
walking = false;
if (nextleft == "free") {
if (Key.isDown(Key.LEFT)) {
xspeed -= speed;
walking = true;
}
}
if (nextright == "free") {
if (Key.isDown(Key.RIGHT)) {
xspeed += speed;
walking = true;
}
}
if (over != "air") {
if (Key.isDown(Key.UP)) {
yspeed = -20;
}
}
if (!walking) {
xspeed *= friction;
if (Math.abs(xspeed)<0.5) {
xspeed = 0;
}
}
if (xspeed>max_speed) {
xspeed = max_speed;
}
if (xspeed<-max_speed) {
xspeed = -max_speed;
}
if (yspeed>y_max_speed) {
yspeed = y_max_speed;
}
if (yspeed<-y_max_speed/1.5) {
yspeed = -y_max_speed/1.5;
}
hero.x += xspeed;
hero.y += yspeed;
level_clip.hero._x = hero.x;
level_clip.hero._y = hero.y;
};
function ground_under_feet() {
y_feet = Math.floor(hero.y/tile_size)+1;
x_feet = Math.floor(hero.x/tile_size);
y_left = Math.floor(hero.y/tile_size);
x_left = Math.floor(hero.x/tile_size);
y_right = Math.floor(hero.y/tile_size);
x_right = Math.floor(hero.x/tile_size)+1;
switch (map_1[y_right][x_right]) {
case 0 :
nextright = "free";
friction = 0;
break;
default :
nextright = "taken";
break;
}
switch (map_1[y_left][x_left]) {
case 0 :
nextleft = "free";
friction = 0;
break;
default :
nextleft = "taken";
break;
}
switch (map_1[y_feet][x_feet]) {
case 0 :
over = "air";
friction = 0;
yspeed += ground_acceleration;
break;
case 1 :
over = "ground";
speed = ground_acceleration;
yspeed = 0;
friction = ground_friction;
break;
case 2 :
over = "ice";
speed = ice_acceleration;
yspeed = 0;
friction = ice_friction;
break;
}
}
// start functions
make_world(_root["map_"+current_map]);
make_hero();
Tile Based Maps Giving Me A Lot Of Trouble..
function createMap(which){
links=[[4, 0x949301, 1]]
arena=new Object()
arena.map=[[0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0],
[0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0],
[0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
town=new Object()
town.map=[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0],
[0, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0],
[0, 1, 2, 2, 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0],
[0, 1, 2, 2, 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 2, 2, 2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 0],
[0, 0, 0, 0, 1, 1, 3, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
k=0
areaArray=[town, arena]
area=areaArray[which]
for(x=0; x<area.map.length; x++){
for(y=0; y<area.map[x].length; y++){
_root.tile.duplicateMovieClip("tile"+k, k)
_root["tile"+k]._x=x*6
_root["tile"+k]._y=y*6
k++
}
}
}
function remove(){
k=0
for(x=0; x<area.map.length; x++){
for(y=0; y<area.map[x].length; y++){
_root["tile"+k].removeMovieClip()
k++
}
}
}
function cm0(){
k=0
for(x=0; x<area.map.length; x++){
for(y=0; y<area.map[x].length; y++){
if(area.map[y][x]==0){ _root["tile"+k].c=0x999999 } //wall
if(area.map[y][x]==1){ _root["tile"+k].c=0x009900 } //grass
if(area.map[y][x]==2){ _root["tile"+k].c=0xA3C1E0 } //water
if(area.map[y][x]==3){ _root["tile"+k].c=0x949301 } //road
k++
}
}
}
function cm1(){
k=0
for(x=0; x<area.map.length; x++){
for(y=0; y<area.map[x].length; y++){
for(i=0; i<links.length; i++){
if(area.map[y][x]==links[i][0]){
_root["tile"+k].c=links[i][1]
_root["tile"+k].i=i
_root["tile"+k].onEnterFrame=function(){
if(_root.p.xpanel==3){
remove()
createMap(this.i)
cm0()
}
}
}
}
k++
}
}
}
_root.pl.duplicateMovieClip("p", 400)
_root.p.c=0x000000
_root.p._x=40
_root.p._y=50
createMap(1)
cm0()
cm1()
that above are the map functions. createMap() makes the actual mc's. cm0() differentiates between dif tile types. cm1() is supposed to look thru the map to see if there r any 'special' tiles that r in the links array. these tiles are the links from one map to another. once it finds one, it gives the tile the color specified in the array and also tells it to wait for the player to be (in this case, ill make it more dynamic later) directly below it. since my function didnt work, i made it easier for now and said if the player is on the third panel, do the stuff.
heres what i wanted to happen: the areaArray has all the maps availabke. the town would be areaArray[0] and so on. this is how createMap() works. what i wanted is that in links, the actual map u'd be linking to would be ure index in the array. so link[0]=[4, 0x949301]
this means tile of type 4 gets that color and links to map 0 in the areaArray. thats what u see in the cm1() function al the way inside. it says createMap(i) and i has already been defined as the place in links where 4 is. so it should be 0, considering there is only one thing in links, but it isnt. its 1. i dont know how. if i enter createMap(0), it works fine, but i want this function to be dynamic, so i have to enter i as the variable, but it is always 1... can anyone help?
Tile Based Game Enemy Allocation
How can i say, in witch level my enemy will be?
theres a code from tonypa tutorials:
// enemies array is in the order [enemy type, xtile, ytile]
myEnemies = [[0], [[1, 6, 1]], [[1, 3, 3]], [[2, 1, 3]]];
I can only say, witch type he/she is and where he/she placed, but how can i say, in witch level he/she will be?
i'm total newbie, please help
Moving Selected Mc's In A Tile-based World..
OK im trying to make a strat game
im trying to make the engine now
the problem im having is making a selected mc move..
Im using tonypas tuts put im modifying them so they can work
with multiple attached Mc's..
So heres my engine so far : 0.205895% complete :P
you click the button down there(I just used whatever button,just to test..)
then u click the map,it places the soldier
then you can click him and it selects him..
(Hold shift and click him to deselect)
when its selected your supposed to click again and its supposed to move..
but as you can see it doesn't..
well heres the script im using to move him:
Code:
function getTarget() {
..
if (Selected != "None") {
if (game["t_"+game.ymouse+"_"+game.xmouse].walkable) {
game.targetx = game.xmouse;
game.targety = game.ymouse;
newSold.moving = true;
trace(newSold.moving);
}
}
thats to give the soldier the new coord's to move to, it also checks if its a walkable tile
and this is the moving function(havent modified it):
Code:
function moveChar(ob) {
if ((ob.x-game.tileW/2)%game.tileW == 0 and (ob.y-game.tileH/2)%game.tileH == 0) {
ob.xtile = Math.floor(ob.x/game.tileW);
ob.ytile = Math.floor(ob.y/game.tileH);
if (game["t_"+ob.ytile+"_"+(ob.xtile+1)].walkable and game.targetx>ob.xtile) {
ob.dirx = 1;
ob.diry = 0;
} else if (game["t_"+ob.ytile+"_"+(ob.xtile-1)].walkable and game.targetx<ob.xtile) {
ob.dirx = -1;
ob.diry = 0;
} else if (game["t_"+(ob.ytile+1)+"_"+ob.xtile].walkable and game.targety>ob.ytile) {
ob.dirx = 0;
ob.diry = 1;
} else if (game["t_"+(ob.ytile-1)+"_"+ob.xtile].walkable and game.targety<ob.ytile) {
ob.dirx = 0;
ob.diry = -1;
} else {
ob.moving = false;
return;
}
}
ob.y += ob.speed*ob.diry;
ob.x += ob.speed*ob.dirx;
ob.clip._x = ob.x;
ob.clip._y = ob.y;
}
ok the truth is that I really dont understand that well the moving function..
and I dont like to use stuff without knowing how it works..
Here is the work function, places the mouse cursor box in the right place
and calls the moveChar() function if the parameters are right
Code:
function work() {
game.xmouse = Math.round((_root._xmouse-game.tileW/2)/game.tileW);
game.ymouse = Math.round((_root._ymouse-game.tileH/2)/game.tileH);
_root.mouse._x = game.xmouse*game.tileW;
_root.mouse._y = game.ymouse*game.tileH;
var ob = newSold;
ob.y=0;
ob.x=0;
if (ob.moving == false) {
moveChar(ob);
}
}
then in a controler MC(witch can perfectly be the first frame..), I have this:
Code:
onClipEvent (enterFrame) {
_root.work();
}
onClipEvent (mouseUp) {
_root.getTarget();
}
The work function is called in every frame and the getTarget only when the mouse is released..
OK the getTarget function is working because it tracing newSold.moving to "true" , so thats good..
Im almost sure the move function is either not working or Im not using it right..
Well I hope I described my problem ok..
If not heres the fla
OK well waiting for a responce
and If anyone can ,it be cool if you explained to me the moving function
[as3] How To Swap Depth For Tile Based Games?
In as2, i could just set the depth based on y, but in as3, that is not possible! The closest function i found is swapChildren(), but still i dont know how can i use it to get similar functionality as y based depth swapping in as2, and since tonypa never finished his as3 based tiles tutorials, i am stumped!! Any ideas?
Tile Based Game Conversation Question
how do I make conversation in tile based game ?
so I want to interact with an NPC by pressing an action button, and a dialogue box come out,some dialogue also have a yes no choice
Does Someone Knows A Good Guide About Tile Based Games?
I have searched every where and I found only 4 but I'm from israel and I don't understand a lot of stuff that wrriten there so if you know a good website that you already tried and it helped you so can you put the link of it here? if you do thanks!
|
|
|