# 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?
Open this post in threaded view
|

## Re: Collision detection in Jack?

 I haven't watched the videos at all. But the video memory is continuous, you can think of it as a 1 dimensional array, and yet it is displayed as a 2D screen. How is that accomplished? For example, if you want to toggle a pixel with coordinates row 10, column 20, how can you find the right address where where this pixel is controlled?
Open this post in threaded view
|

## Re: Collision detection in Jack?

 In reply to this post by A_Random_Person Hi I might be jumping in here and not knowing what i'm talking about, so there's my caveat. 1) There is somewhere on this forum a list of various programs written in jack which are definitely worth a look for some excellent solutions to problems. 2)Complicated maths, decimal maths, 3d graphics have been got around by creating basically predefined tables which are poked into memory on game initialisation, ie the work has been done outside of jack, then ported in, by the programmer tediously (i'd guess, but maybe there’s a way around that too) inputting the relevant data into the program, which it then uses later.. I'm sure you're already thinking about this..but there's more than one person reading your posts ! Good luck !