Welcome, Guest
Username: Password: Secret Key Remember me

TOPIC: Pacman on an 8x8 LED Matrix

Re: Pacman on an 8x8 LED Matrix 9 years 3 months ago #14885

  • retrobrad
  • retrobrad's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 1
  • Thanks received: 8
Hi everyone.

I just thought i'd post some details of my first real project in swordfish.

It is a pacman type game which uses an 8x8 LED matrix.

At the moment you are able to move about the screen (which has a total game area of 32 x 32 pixels) if the screen is at any of the extremes, it will allow just your pacman (a single pixel) to move around. If you try and move any further away from an extreme edge of screen, it will be the whole screen that shifts to reveal more of the 32 x 32 pixel area.

An animated gif (although poor quality) says it better than text: please note that this animation is running at a very reduced frame rate and as such can be hard to follow what is happening on the display.



I have also made it so that you can warp from screen edge to screen edge (just like in the original game)

i have started to experiment with one 'ghost' (bad guy) on the screen. At the moment he just follows you everywhere but doesnt hurt you (a simple x and y co-ordinate system whereby the ghost keeps checking to see if his x and y co-ordinates are greater or less than yours in order to seek you out.)

Eventually I will make it so that there are multiple ghosts who will follow you around (while also avoiding walls rather than going through them.

And of course, there will be loads of levels and pellets to eat along the way. I am almost certain that I will make the final version with an RGB matrix rather than this RG matrix I am using at the moment.

i have to say that basic has been alot nicer to work with on something like this, as compared to assembly...
Attachments:

Re: Pacman on an 8x8 LED Matrix 9 years 3 months ago #2353

That's really neat so far Brad!

What method are you using to work with such a large screen? An Array of long words?

Pathing for the bad guys sounds like an interesting issue - Do they usually start hunting only when your on the "same screen" or only when they have line of sight on a certain path?

Re: Pacman on an 8x8 LED Matrix 9 years 3 months ago #2355

  • retrobrad
  • retrobrad's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 1
  • Thanks received: 8
Thanks Graham.

You got it in one, I am using a 32 bit array of longwords to hold the game area data. To move the screen up and down, I just start drawing from a different longword in the array. To move the screen left and right, I just shift the bits in the eight arrays that are on the screen at the time.

Here is a little bit of code which deals with updating the enemy:
Sub update_enemy_x()       
    enemy_on_screen_x = enemy_1_area_x - board_position_x   
    If enemy_1_area_x > character_area_x And enemy_delay_x = 0 Then
        Dec(enemy_1_area_x)
        enemy_delay_x = 50
    ElseIf enemy_1_area_x < character_area_x And enemy_delay_x = 0 Then
        Inc(enemy_1_area_x)
        enemy_delay_x = 50
    EndIf
End Sub

Sub update_enemy_y()
    enemy_on_screen_y = enemy_1_area_y - board_position_y
    If enemy_1_area_y > character_area_y And enemy_delay_y = 0 Then
        Dec(enemy_1_area_y)
        enemy_delay_y = 50
    ElseIf enemy_1_area_y < character_area_y And enemy_delay_y = 0 Then
        Inc(enemy_1_area_y)
        enemy_delay_y = 50
    EndIf
End Sub

The first line for each deals with storing a byte of data to determine whether the x, y co-ordinates of the enemy falls within the 8x8 pixel area that is currently displayed on the screen.

So let's say that the enemy is located at the co-ordinates x = 24 and y = 18.

Then let's say that the bottom right pixel (co-ordinate) of the currently displayed screen is x = 20 and y = 15.

The line of code takes away the enemy's x and y positions from the x and y co-ordinates of the bottom right pixel of the screen. So we first take care of x:

24 - 20 = 4

and then y:

18 - 15 = 3

So therefor, (with reference to the bottom right pixel of the screen) the enemy will be displayed on the screen at the co-ordinates 4, 3 (which is the fourth pixel across and third pixel up)

If the enemy co-ordinates are ever greater than 7 pixels away (from the reference point which is the bottom right corner of the display), this means it will not be drawn on the screen.

As for your other question, you can see in the code that the enemy just keeps checking to see if his co-ordinates are greater than or less than the pacman's co-ordinates. he then increments or decrements his x/y co-ordinates in order to hunt down the pacman.

This is a very basic way of doing it with the downfall that the enemy is not restricted by walls I.E. he can move through walls. This is where all the fun and trial and error comes into it!
Time to create page: 0.230 seconds