Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 shooting from a picture
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
w00t




PostPosted: Thu Dec 16, 2004 5:17 pm   Post subject: shooting from a picture

Okay, I think i've officially hit the wall of STUPIDITY and it hurts!

I'm making a space invaders game for my ISU and now i have the ship movement the alien movement and i even have the extremly chessy music.. but how can i get the space ship to shoot, i can draw a line but how do you draw a line from the "spaceship" when its always moving?

I dont know if thats very clear, if it isn't ill give it another go at it..


thnx alot
w00t
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Dec 16, 2004 5:25 pm   Post subject: (No subject)

your question is vague, but my guess would be that you should draw your line independant of the ship. Such the line has a set of its own variables that are synced to the ship when the line is created, but are independant afterwards
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Delos




PostPosted: Thu Dec 16, 2004 5:25 pm   Post subject: (No subject)

You're 'line' can be considered an object with behaviours and characteristics.
For example, it has an x- and y- value, a life-span, a length, a power setting, etc etc.
It terms of keeping the line in the same place as the ship...simply ensure that the x-values always match up (assuming your ship can only move left-right). If you have more complex movement, then keep the x- and y- values the same. Of course by 'the same' I mean 'in the same place that they should be, be it at SpaceShipPic.x and SpaceShipPic.y or (SpaceShipPic.x + 4) and (SpaceShipPic.y + 7)...assuming that (4,7) pixels away from the bottom left hand corner of your pic is the part that looks like the gun...'

Make sense? No? Ah well.

Make required x- and y- values match up.
w00t




PostPosted: Thu Dec 16, 2004 5:46 pm   Post subject: (No subject)

okay
i have my space ship move on the X axis left and right, when i press down its suppose to shoot a "laser / projectile " at the evil furby. i can get the collison but how do i get the "porjecitle" to shoot from my ship.. i didn't understand the previous post completly..

if you want code it post it for you.
Cervantes




PostPosted: Sat Dec 18, 2004 12:14 pm   Post subject: (No subject)

If I understand correctly, you are now looking more towards shooting bursts of lasers as opposed to a constant stream. If that's the case, Flexible Arrays are going to be your best friend. Smile
MihaiG




PostPosted: Mon Dec 20, 2004 5:16 pm   Post subject: (No subject)

check my rain program for some ideas.. at this page

http://www.compsci.ca/v2/viewtopic.php?t=6885&sid=227ef0dacda4bc5ae634ebd9a9c12334

it almost gives the same effect but make so it draws one line.... Smile
Cervantes




PostPosted: Mon Dec 20, 2004 8:11 pm   Post subject: (No subject)

I fail to see how that relates to the question asked.
(Note that the above statement is not a question. If you see it as one, please, see it as a rhetorical question.)
MihaiG




PostPosted: Mon Dec 20, 2004 8:34 pm   Post subject: (No subject)

the rain is essentialy like the laser.... it draws its self thne again 1 pixel down..... using an array... but you can make it for just one buller/ beam every 100ms so you don't get like .... or the moving speed so it does go off the screen in 1 / 2 *s
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Dec 21, 2004 7:49 am   Post subject: (No subject)

The difference is, you will always have a specific number of "lasers" (or raindrops) if you use an array. However, when you use a flexible array, you've got just the right number of elements to store the bullets (or lasers) that are onscreen.
w00t




PostPosted: Tue Dec 21, 2004 8:28 am   Post subject: (No subject)

okay, thnx for showing me how to shoot, but im still a little foggy on this question..

How do i shoot from a picture if its constantly moving along the X-axis ... because if i wantto draw a line that was green it would be

drawline (10,10,10,50,green)

but now I"ve hardcoded the line and can't make the x and y coordinates a varible unless you can. then please inform me on how to do so...

tnx in advance

w00t
Delos




PostPosted: Tue Dec 21, 2004 9:52 am   Post subject: (No subject)

code:

var x, y1, y2 : int := 0
y1 := 20
y2 := 100

for i : 1..20
   drawline (x, y1, x, y2, green)
   delay (20)
   x += 3
   cls
end for
Cervantes




PostPosted: Tue Dec 21, 2004 9:56 am   Post subject: (No subject)

Create a variable to store the position of your picture (I'll call it shipX). Since Pic.Draw draws from the bottom left, shipX will not be the middle of your ship, but the left of your ship. So, in your if statements, you'd have to take into account that fact. Personally, I prefer to have my variables store the middle value of the picture. To achieve this, try doing this:
code:

Pic.Draw (ship, round (shipX - (Pic.Width (ship) / 2)), 10, picCopy)

Now, say your gun is in the middle of the ship. Just create a new element of your flexible array and shoot a bullet out, using shipX for that bullet's x value (note that you set the x value when you fire the bullet. You don't change it after it has been fired).
w00t




PostPosted: Tue Dec 21, 2004 6:57 pm   Post subject: (No subject)

Thanks Alot!

It works, as soon as i have the game complete ill post it, it even comes with amusing animations! it shall be a success

tnx w00t Wink
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: