Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Tile based Movement and Tile based collision

Author
Message
sprcoll
12
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 6th Oct 2015 20:55
Hello all together, i hope that someone will help. I want to code a game similar to pac man. i want make it tile based. I try this since weeks but don´t come to the target.
The following things i have found out and i understand. When i wan´t to make something new i start as easiest as possible, in this case a one dimension array instead a string array.

first, a one dimension array:

DIM Tile[5]
Tile[1] = 1
Tile[2] = 1
Tile[3] = 1
Tile[4] = 2 here the player has to stop
Tile[5] = 1

if i want to know on which tile the player is, i calculate:

tilesize = 10

tilex = (px / tilesize)
tileY = (pY / tilesize)

i want to make the movement as following:

if r_arrow = 1
move = 1
elseif r_arrow = 0 and move = 1
px=tilex*tilesize
tilex = tilex + 1
endif

The collision as:

if px ist on tile[4] move = 0

What i don´t understand is how i can assign the tile position to the array position,
maybe something like this:

for x = 0 to 5

if move = 1 and tile[x] = 2
move = 0
endif
next


As describe in the first lines a try it since weeks, but i don´t go ahead.
I would be very happy, if someone helps me.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Oct 2015 14:13
it will be much easier if u use a 2d array
DIM Tile[10,10]
Tile[1,1] = 1
so you can request the tile number with
tilex = (px / tilesize)
tiley = (py / tilesize)
nr=Tile[tilex,tiley]
u need to check the tile item before you move the player, so you can cancel the x or y movement.
u should use many functions, else u have a problem to understand your code in the end.
AGK (Steam) V2 Beta .. : Windows 10 Pro 64 Bit : AMD (15.7.1) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
sprcoll
12
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 8th Oct 2015 20:42
Ok, thank you. I will work with it on the weekend. I hope i come finally to the target.
sprcoll
12
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 24th Nov 2015 20:04
Hello,
many thanks to Markus. What i didn´t know, was the line (nr=Tile[tilex,tiley]). With this line my code works. Now i want to put a text file to my array. The following things i have found out:

OpenToRead (1, "map.txt")

string$ = ReadString (1)

CloseFile (1)

So, i can print the string$, but how can i put the string to my array, i would be very happy if somebody help me? I have searched the forum, but i haven´t found something like this, thank you.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 24th Nov 2015 21:39 Edited at: 24th Nov 2015 21:41
You can either iterate through the string that you have read, or you can read individual bytes from the file. Something like:


or

V2 T1 (Mostly)
Phone Tap!
Uzmadesign
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 25th Nov 2015 22:21
You might find my Platypus game thread of use, at the start I have some code for levels and loading files to display them.

https://forum.thegamecreators.com/thread/215384
The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
sprcoll
12
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 6th Dec 2015 16:20
Hello,
thank you for your postings. I need a little bit more help by my code. I hope that someone will help. I use the following:

dim tile$[6]
OpenToRead(1,"map.txt")
for tilex=0 to 5
string$ = ReadString(1)
tile$[tilex]=string$
print (tile$[tilex]) the print works, i can see the signs from the file
next tilex
closefile (1)

feature$ = tile$[tilex]

and then the player movement and the collision query.

What is wrong?
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 8th Dec 2015 17:01 Edited at: 8th Dec 2015 18:22
This might not be what you are looking for, but it does demonstrate collision checking in a grid based system.



No media needed, very basic, with comments.
sprcoll
12
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 10th Dec 2015 19:57
Hello,
many thanks to this posting. I will try it on the weekend. I think, now i can make my movement and collision ready.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Dec 2015 19:06
When you say tile-based movement, does that mean your character moves only from square to square? Or can its movement be more fluid as in per-pixel but within a grid-based word?

This is DB code, but you might find this useful:
https://forum.thegamecreators.com/thread/203589

\"I like offending people, because I think people who get offended should be offended.\" - Linus Torvalds
sprcoll
12
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 21st Dec 2015 20:05
I want to move from tile to tile (square to square). Is this the best method for a game similar to Pac-Man?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Dec 2015 07:27
Pacman pretty much uses the same graphics every level for the most part. And considering that game used to run on like 4k memory, I think you're ok loading everything you need and leaving it in memory until it's time to quit the game.

As far as movement goes, pacman has pixel movement, but is only controllable from square to square. Meaning, you can't change direction mid-tile. Here's a rough example:



This is just a very basic example. The actual pacman game continues moving in the same direction until the user either triggers a direction change or it hits a wall. But this shows how you can move from tile A to tile B smoothly. Btw, I didn't draw pacman, I drew his southern cousin, Cooter.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Attachments

Login to view attachments
spasski
AGK Backer
11
Years of Service
User Offline
Joined: 2nd Jan 2013
Location: Amsterdam
Posted: 29th Dec 2015 18:42
Thanks a lot Phaelax for sharing the pacman code example, very valuable stuff

Login to post a reply

Server time is: 2024-11-25 13:39:35
Your offset time is: 2024-11-25 13:39:35