Introduction to our course

Welcome to my blog, Digital Communications, which will document my progress and activities throughout the BTEC Interactive Media course.

Wednesday, 2 February 2011

Basic game movement in flash actionscript a la PacMan!

Hi,

grid based movement using arrays
Been playing around in actionscript. Got multi-dimensional arrays working so that means I can define a maze level in this array and have the code traverse this and display the relevant blocks of the maze (in this case its just either a wall or nothing).
Using the same array I am able to move the player about and detect if there is a wall in the way and block the movement.
The green and red are done in the same way, except for the their movement, it is simply a random number between 1-4 which determines which way they will try to move (1=left, 2=right, 3=up, 4=down).

a code snippet
It's a basic example of using arrays to track movement and collisions. Think Pac-Man!
You could for instance have sections of the grid that are power-ups/keys etc. which when you move over them change something. You just check which position you are on the grid, look into the array at this position and get what's there.

chris

No comments:

Post a Comment