# Collision detection in Jack?

8 messages
Open this post in threaded view
|

## Collision detection in Jack?

 Is there a efficient way to implement collision detection in Jack? I am making a Pac-Man game, and I need a fast (and simple) way to detect wall collision. How can I do this?
Open this post in threaded view
|

## Re: Collision detection in Jack?

 Pacman is a relatively simple game, but even it will require some sort of model of the game world. That is, you need to know where there are walls, dots, large dots that turn pacman into the hunter, cherries, ghosts, pacman itself. I'm sure I missed something. You'll need to know where each of those objects is at any given time, so you better make a model for them. In the game loop you will just have to update the model depending on what happens, like key presses, and ghosts moving and turning, and you need to update the screen as well. The collision detection in the game model can be much simpler than general purpose one. Hint: even though the object appear to have different forms, you can treat them as squares. Except the walls, of course. But they are quite static anyway, so you'd want to represent them differently.
Open this post in threaded view
|

## Re: Collision detection in Jack?

 I am currently representing the walls as a simple 2D array. When Pac-Man moves forward, before it is rendered onto the screen, it will check the 2D array to check if there is a wall.
Open this post in threaded view
|

## Re: Collision detection in Jack?

 The only problem is that constructing a 2D list in Jack is very tedious. my Pac-Man maze will require 32×28=896 cells. Is there a fast way to construct lists (like in most languages, constructing a list will only require ` = {, , , ... }`)
Open this post in threaded view
|

## Re: Collision detection in Jack?

 Can you think of a way to easily map 2d grid to a 1d array? (Hint: look at the video memory mapping)
Open this post in threaded view
|

## Re: Collision detection in Jack?

 I cannot find any videos with their name containing "memory mapping" in week 3. Can you please be a little more precise?