Detecting front and back?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
kroghet
Posts: 5
Joined: Sat Feb 18, 2012 10:53 pm

Detecting front and back?

Post by kroghet » Thu Feb 23, 2012 5:09 pm

Hey I am trying to make a simple game in Livecode. I have made a player, and some enemies.

My problem comes when i want to "shoot" enemies down. I have collection check, and they go away when they hit my "player", and also when I shoot. But is there a way to see what way is forward?
Right now i "kill" objects 150 in front of my player. But I want to only be able to shoot the objects that are in front, so if I turn 180 degree I don't want to kill the objects behind me.

I guess I need some way to find out what way my "player" is facing, so I only do a action in one direction.

Btw I am very new, and I am just following the Game academy tutorial and modifying it, but this problem I can't seem to figure out without expert help.

Here is my code that handles my shooting. As I said I am very new in this, so sorry if it does not follow normal conventions for coding :)

on handleShoot
if sShoot is true then
repeat for each key tEnemy in sEnemyNames
put the right of button "rocket" into tRocketlocRight
add 150 to tRocketlocRight
put tRocketlocRight into field "rocketfield"
if the left of button tEnemy < tRocketlocRight then
add 1 to sPlayerHit
put sPlayerHit into field "enemyfield"
delete button tEnemy
delete variable sEnemyNames[tEnemy]
end if
end repeat
end if
end handleShoot

Any help appreciated

Thx

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Detecting front and back?

Post by sturgis » Thu Feb 23, 2012 5:44 pm

if you are setting the angle of your char you can most likely use sin and cos to generate factors that can be used to check facing and distance.

I did something similar with an asteroids game that i'm workign on. Its not even close to done, i'm sure if I start working on it again things can be tightened up considerably, and so far my commenting isn't much, but if you want to look at what I have so far i'd be fine with posting a link to the stack.

So far you can use the arrow keys to rotate, up arrow to accelerate. Space bar fires a bullet at the angle the rocket is facing, only 1 shot onscreen allowed at a time so when the bullet exits the screen, its deleted. The method I used to pick the start position for the shot is clunky. There is a lesson in one of the revUps that explains how to set up a game with a shooting canon. If I can find the link to that i'll post it here also.

Will go ahead and link the asteroids start just because.

http://dl.dropbox.com/u/11957935/Asteroids.livecode

kroghet
Posts: 5
Joined: Sat Feb 18, 2012 10:53 pm

Re: Detecting front and back?

Post by kroghet » Thu Feb 23, 2012 6:20 pm

Thx a lot sturgis, I will try and have a look at the stack, it is very helpful to see what others have done, and figure out how this programming thing works :)

And a link to that revUps if you stumble over it would be very nice as well.

Thx mate

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Detecting front and back?

Post by sturgis » Thu Feb 23, 2012 11:59 pm

Found the link. http://runrev.com/newsletter/october/is ... etter3.php This is the link to part 1, you may have to dig around to find the meaty parts. Don't remember how it does what it does off the top of my head but seemed pretty interesting at the time.

kroghet
Posts: 5
Joined: Sat Feb 18, 2012 10:53 pm

Re: Detecting front and back?

Post by kroghet » Fri Feb 24, 2012 5:48 pm

Thx again mate. I will try and read that and see if I understand it :)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”