Author Topic: Collision for a Terria like game?  (Read 1495 times)

0 Members and 1 Guest are viewing this topic.

Offline Piguy-3.14

  • LV3 Member (Next: 100)
  • ***
  • Posts: 41
  • Rating: +1/-0
    • View Profile
Collision for a Terria like game?
« on: June 17, 2013, 01:09:51 pm »
Okay so I am implementing physics into my game, Picraft 2 and need help on testing sprite collision. It is not in tilemap and uses Pt-off(_,_,pic_ to display sprites. I need to make it so that when the player places a block he can't walk/fall through it. I do not need anything complex just a simple way to test collision. Here are to methods that I would like to use:
One that detects a whole sprite and keeps the player from entering the 8*8 radius of the sprite, even if the pixels are white(remember these will be placed by the player, not be there to begin with) Also my method of destroying a block is by placing a blank sprite over it, and I want to make it so the player can walk through the 8*8 blank square, aka the destroyed block, which is why method one would not work.

Method two however would detect if two black pixels touched each other and would then return the player to the position that he was in exactly before he tried to go through a sprite that had black pixels boardering  it. In other words I want to make it so that the player can only pass through white pixels not black if you know what I mean. Like I said this would be the PREFERED way, but if you know another way that would be simpler that would most likely be better, as I do not want a very confusing code to deal with. Can someone show me a code and explain it to me? Here is a sample of my method of outputting sprites in case you need it:
:[]->pic1A
:.you insert the sprite data in the brackets
:If getKey(34)
:Pt-off(W,H,Pic1A
:End
That is a basic idea of what the code looks like(W H are variables for XY that place a block at the current location of the cursor)(getKey(34) is just an example I use multiple keys for placing blocks)
Remember I want a SIMPLE, easy to understand code for detecting black pixels colliding with other black pixels if possible, that can detect user placed and user destroyed blocks. If you know a solution please tell me, I would be very grateful.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7918
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Collision for a Terria like game?
« Reply #1 on: June 17, 2013, 01:39:43 pm »
for collision you should have a array with all the different kind of blocks where you can walk on and compare the character position to the one in the array.

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Piguy-3.14

  • LV3 Member (Next: 100)
  • ***
  • Posts: 41
  • Rating: +1/-0
    • View Profile
Re: Collision for a Terria like game?
« Reply #2 on: June 17, 2013, 04:13:37 pm »
...what? Sorunome I have no idea what you mean lol. I need a more detailed explanation and preferably some code to go with it...

Offline XiiDraco

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 513
  • Rating: +32/-5
  • Forget the numbers, just call me, Recreation.
    • View Profile
    • Black-Lark Games
Re: Collision for a Terria like game?
« Reply #3 on: June 17, 2013, 04:22:49 pm »
Oh, lol. I tried to make a game like terraria, but lost my data,  :(.
Any way, when you picture an array, picture 2 lists, one handling data for the X then one handling the data for the lists that contain thoses x lists. Arrays are pretty much 2d lists. they have an X and Y coordinate for the list instead of just x.
Think of it like a world in terraria. You have an X and Y for that block(the X and Y location of that blocks data in the array) and then the block say grass. in the array you can give grass the data value 1 so whnever it reads 1 grass is there.

I never really got collision detection from these arrays down. But there is an attempted explaination.

Offline XiiDraco

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 513
  • Rating: +32/-5
  • Forget the numbers, just call me, Recreation.
    • View Profile
    • Black-Lark Games
Re: Collision for a Terria like game?
« Reply #4 on: June 17, 2013, 04:32:05 pm »
If you really want to make it o you detect collision throuh pixels, all of the blocks will have to have a black edge. But if you want to, use pxl-test. This will give you a 1 or zero back, So you can test the pxls in front of he moving object and determine wether it hit something or not.

Please excuse the double post my PsVita is being derpy.
« Last Edit: June 17, 2013, 04:33:02 pm by XiiR3CR34T10N »

Offline DJ Omnimaga

  • Former TI programmer
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55847
  • Rating: +3151/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: Collision for a Terria like game?
« Reply #5 on: June 17, 2013, 05:19:57 pm »
Please excuse the double post my PsVita is being derpy.

The PS Vita uses Internet Explorer? O.O
« Last Edit: June 17, 2013, 05:20:22 pm by DJ Omnimaga »
In case you are wondering where I went, I left Omni back in 2015 to form CodeWalrus due to various reasons explained back then, but I stopped calc dev in 2016 and am now mostly active on the CW Discord server at https://discord.gg/cuZcfcF



Official Website |T-Shirt store | Reverbnation | Facebook | Youtube | Twitter | Spotify

Offline XiiDraco

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 513
  • Rating: +32/-5
  • Forget the numbers, just call me, Recreation.
    • View Profile
    • Black-Lark Games
Re: Collision for a Terria like game?
« Reply #6 on: June 17, 2013, 08:21:39 pm »
Well not IE, its sony's little brand thing.

Offline tr1p1ea

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 647
  • Rating: +110/-0
    • View Profile
Re: Collision for a Terria like game?
« Reply #7 on: June 17, 2013, 08:25:52 pm »
So you are after sprite<->sprite collisions?
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."


Offline Piguy-3.14

  • LV3 Member (Next: 100)
  • ***
  • Posts: 41
  • Rating: +1/-0
    • View Profile
Re: Collision for a Terria like game?
« Reply #8 on: June 17, 2013, 08:33:33 pm »
Ya I am I'm pretty sure