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.

Newcomers AppGameKit Corner / Trying to make tipping blocks game...need help

Author
Message
sandra_rose
3
Years of Service
User Offline
Joined: 14th Jun 2021
Location:
Posted: 14th Jun 2021 02:42
Hi,

I am trying to make a blocks game similar to tipping blocks where you stack blocks on top of the previous one. The games basic functions work fine, however the collision detection system is a little buggy. I am trying to limit it so it only counts detection on the top surface of the previous one. However, this does not work as expected and it still counts collision on side.

I am trying to check whether collision is on tops side of previous block with if statement on line 128, however it does not work as per my logic and the block goes right through. The detection system only works when I switch my "<" sign to a ">" sign, but this counts side collisions as valid which I don't want. My method for checking this is using statement: if (GetSpriteY(count) + GetSpriteHeight(count)) <= GetSpriteY(count - 1), where count is the top block and (count - 1) is the previous block.

Losing my hair trying to debug this...any help would be appreciated.

Thanks in advance

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Jun 2021 17:31
Check the X

untested but should work



PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Jun 2021 18:12
Is this what your looking for?

Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 17th Jun 2021 13:11 Edited at: 17th Jun 2021 13:35
@ PTC

Quote: "if CheckBlock(sprNext, sprLast)"

This is interesting, because all this time I have just used Global Flag variables and set their values in the functions, rather than using the function as a flag by returning a value for the function.

This is cleaner. (for single flag conditions)

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 17th Jun 2021 16:45
Yeah I prefer my functions to be self contained and keep global variables in the global scope, allowing functions to set globals can end up causing all sorts of hard to find problems down the line, for a multi state return I'd just use a 'Select' and some constants but take the same approach.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Jul 2021 04:22
I think I remember seeing this question on stackoverflow.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
yoel12344
3
Years of Service
User Offline
Joined: 5th May 2021
Location:
Posted: 14th Jul 2021 11:15
shaere the code, from what your saying i think its collision prediction, like your trying to predict collision from the top before it hits the hitbox from the top (hitbox.y-20).

hers how i did it a few days ago :



the use will be like:

topspr = 1 //top sprite id
bottomspr=2 //bottom sprite

if yhitp(topspr,bottomspr,0,-10) then print("hit from top")

here we predict if topspr is -10 pixels from the hitbox.

doesn't work with rotated rectangles only with axis aligned bounding boxes (aabb).

Login to post a reply

Server time is: 2024-11-23 08:06:05
Your offset time is: 2024-11-23 08:06:05