Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

conditional branch> pictures coordinates

Hey all,
I am making a short fun space invader-esque game via events.
I am using pictures, with coordinates as the player and enemies.
I have lasers and movement figured out.

Projectile/Enemy Interaction
I had it set so that If the laser coordinate == enemy coordinate, the enemy gets hurt.
http://img248.imageshack.us/img248/6254/71570963re5.png[/IMG]
But then I realized, picture coordinates are only one pixel!

So if the little green dot doesn't hit the other little green dot, it's a miss, even though it looks like it should have been hit :\
http://img63.imageshack.us/img63/9021/49718337cs6.png[/IMG]
So my question is this.
How can I RGSS this:
--------------------------------------
Event conditional branch>script :
If Picture[id]coordinates are within 20 pixels of Picture[id] coordinates
#first pic[id] is the laser, the second pic [id] would be the enemy
then: result
--------------------------------------
so the end result would be, if the purple circles touch, then it's a hit.
http://img406.imageshack.us/img406/7355/69483044ve8.png[/IMG]

Thanks in advance!
 
I don't claim to know RGSS, but I can tell you what I would do in a normal programming language. If you can find the syntax, you should be ok.

There are a few ways to do it, but some would be better than others. You COULD set up an array of all the possible coordinates based on the size of your picture, and then check the laser with that, but that would be very slow.

Now, I'm not sure, but does the picture class you are using have dimensions variables? It probably does -- and what I mean by dimension variables is height and width. So, can you say picture[id].width() and get the width of the particular picture? If you can, this problem is easy.


I assume the coordinates of the picture are the top left corner of the picture.


if((laserpictureID.xcoordinate > (enemypictureID.xcoordinate) AND laserpictureID.xcoordinate < (enemypictureID.xcoordinate + enemypictureID.width)) AND (laserpictureID.ycoordinate < (enemypictureID.ycoordinate) AND laserpictureID.ycoordinate > (enemypictureID.ycoordinate - enemypictureID.length)))

hit = true;

Now, I realize that is very sloppy, and there may well be a built in function that performs the task better.

I would also just create a function that does all that logic, call it "isHit", and make the parameters the two pictures you wanna check. Have it return a boolean value, and then you can just say:

if(isHit(laserpictureID, enemypictureID))
enemyhp = enemyhp - 10;


or whatever you wanna do. Granted, this may not be the BEST solution, but again, I don't know rgss, and I don't really code games, either.
 

arev

Sponsor

Actually, if you do it like this, then the hit would counted too early - when the rectangles of the sprites would overlap. And if a sprite is round it woud not look good. So, my guess is like this:
display those pictures with centered coordinates, and set ox and oy so the actual pixels of the sprite (position) would be in its center. Then count the distance between them, and if its less than, let's say, that round sprite radius - count a hit. To check the coords of picures you'd first need to add a little something to the Spriteset_Map class:
Code:
class Spriteset_Map
attr_reader  :picture_sprites
end
This will let you read the pictures from outside that class. Now, similar thing in Scene_Map:
Code:
class Scene_Map
attr_reader  :spriteset
end
Now you can read the coords. Like this ('Script' command):
Code:
$scene.spriteset.picture_sprites[id].x
ID is the number of a picture.
Check the distance with an expression:
Code:
Math.sqrt((pic1.x - pic2.x)^2 + (pic1.y - pic2.y)^2)[code]
where pic1.x is the previous code ($scene.spriteset.picture_sprites[1].x).
As you can see, it's a real pain in the ass to do it with events this way :/ And, what's more important, it's really ineffective.
Is this going to ba some mini game? Or a stand-alone? If the second, I may be able to help you. I have a shooter engine started, but it's quite far from completing, and I won't be able to work on it anytime soon (but I will finally). Here's a small sample: 
[url=http://rapidshare.com/files/57364115/gal20.rar.html]http://rapidshare.com/files/57364115/gal20.rar.html[/url]
The collisions are not there yet, but I've already tested a way to do it from scratch and it works perfectly (so there won't be any problems with implementing them). Ok, enough said. Play the demo : )

p.s. It's mouse-controlled ; )
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top