ForumsProgramming ForumHi Guys, Need help :D

25 9946
MaTX
offline
MaTX
18 posts
Nomad

Hi! I want to make a game with some blocks but not tetris and i need a hand .
You know the minigame from professor layton?
http://i.ytimg.com/vi/WsRcWs_aBVI/0.jpg
In this one you have to change the position of the spheres, in mine you have to put a wooden block out of the game screen.

I started studying programming just a month ago and i'm a noob yet.
The first test i did i used this code to move a block:

[code]
public function DocumentClass()
{
block1 = new Block(100, 200);
addChild ( block1 );
block1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
block1.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}

public function mouseDownHandler(evt:MouseEvent):void
{
var object = evt.target;
// we should limit dragging to the area inside the canvas
object.startDrag();

}

public function mouseUpHandler(evt:MouseEvent):void
{
var obj = evt.target;
obj.stopDrag();
}
[/Code]

Whit this code i can move the block everywhere on the screen: that's not what i want.
How can i write a code that give me the possibility of moving on lines set in advance?
I explain better: the blocks have to move in only four directions: up, down, left and right and have to stop or don't move when collide with another block.

I know, i'm noob! That's why i'm here!
Thanks in advance

  • 25 Replies
MaTX
offline
MaTX
18 posts
Nomad

DocumentClass() is the constructor.

plasmafish
offline
plasmafish
252 posts
Nomad

Are you trying to make something that has collision detection like tetris?

MaTX
offline
MaTX
18 posts
Nomad

I want to do this:
http://www.appbite.com/wp-content/uploads/2009/05/iphone-app-review-unblockme.jpg
You have to put out the red block moving the others

plasmafish
offline
plasmafish
252 posts
Nomad

What you are trying to do is create a collision detection engine. You will either need to program your own or select a premade one.

Tell me if this helps you.
http://www.flashkit.com/movies/Games/Full_Game_Source/Rush_hou-Fabio_Ma-12265/index.php

plasmafish
offline
plasmafish
252 posts
Nomad
MaTX
offline
MaTX
18 posts
Nomad

This is Great, thanks man

MaTX
offline
MaTX
18 posts
Nomad

This is coded in actionscript 2.0 and my using 3.0 but i think it's always a great base.

plasmafish
offline
plasmafish
252 posts
Nomad

No problem, try to model your AS3.0 after this game if this is what you were trying to accomplish.

SlimyGames
offline
SlimyGames
42 posts
Nomad

Plasmafish you seem to be a nice person by helping MaTX out, when i was beginner at actionscript i had to figure out everything by myself.

I wish i had got help with some actionscript when i was a newbie.

MaTX
offline
MaTX
18 posts
Nomad

World is cruel

This is my plan:
I will divide the screen in an immaginary Grid: if it is 400x400 my grid will be divided bye ten 40x40 dowels.

I will have one array of boolean types with ten elements: true if the dowel is taken, false if it's free.
Everytime a player moves a block i take mouseX and mouseY when he click on the block and then mouseX and mouseY when he release the block.
Then i will subtract them from the old x and y obtaining xMovement and yMovement.
Then i will do this:

if (Math.abs(xMovement) > Math.abs(yMovement))
{
//moves on x
if (movimentoX<0)
{
direction = 'left';
}
else
{
direction = 'right';
}
}
else if (Math.abs(movimentoX) < Math.abs(movimentoY) // muove su Y
{
//moves on the y
if (movimentoY<0)
{
direction = 'up';
}
else
{
direction = 'down';
}
}


Then, after obtaining the direction variable i'll check in what dowel the block is.
Then i'll take the direction (imagine the block is on dowel 3) and..

http://i46.tinypic.com/2irwutg.png

If the direction is "up" i will subtract 10, if it's "down" i will add 10, if it's "left" i will subtract 1, if it's "right" i will add 1.
Then i'll make a check if the move is legal and if it is, i will move the dowel on the number i found.


I think it can work!

MaTX
offline
MaTX
18 posts
Nomad

The code is not correct:

if (Math.abs(xMovement) > Math.abs(yMovement))
{
//moves on x
if (xMovement<0)
{
direction = 'left';
}
else
{
direction = 'right';
}
}
else if (Math.abs(movimentoX) < Math.abs(movimentoY) // muove su Y
{
//moves on the y
if (yMovement<0)
{
direction = 'up';
}
else
{
direction = 'down';
}
}

MaTX
offline
MaTX
18 posts
Nomad

http://nonmichiamofredo.altervista.org/BlockQuest.swf
It doesn't work XD
I have to change something..

MaTX
offline
MaTX
18 posts
Nomad

Correct link:
Here

MaTX
offline
MaTX
18 posts
Nomad

Now this work

plasmafish
offline
plasmafish
252 posts
Nomad

Hmm, I don't quite understand how to play or what I am supposed to do. Are you trying to map that one block to movement with the arrow keys? Whatever the problem is, just keep at it.

It is an optical illusion also, you might want to fix the size and color scheme. Maybe put it on a background and only show those lines for debugging purposes and not in the final game.
http://files.sharenator.com/black_dots_optical_illusion_Optical_illusions-s390x325-13679-580.gif

Showing 1-15 of 25