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

Username:   Password: 
 RegisterRegister   
 Could use some help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
CyberStorm




PostPosted: Sun Jun 05, 2011 4:25 pm   Post subject: Could use some help

What is it you are trying to achieve?
in my shooting game, when an enemy dies the health, which is stored in a flexible array, has to be deleted from memory so the image of it doesnt appear anymore on the screen.

What is the problem you are having?
this involves moving down all of the array values stored above the array slot that needs to be deleted, and apparently something is not coded right because when i sometimes kill an enemy, another enemy disappears instead of the one i was aiming at. i hope you could help me pinpoint the specific logic error in the following code, or give a few advices about where to look for the error in the rest of the program.
i would try and output health values in the array and solve this on my own, but im using 'cls' a lot due to the animation necessities, and i cant figure out how i could ouptut the values in a separate window so cls doesnt interfere.


Post any relevant code

Turing:


for i : 1 .. numtarg
                            if xshot >= x1 (i) and xshot <= x1 (i) + 30 and yshot >= y1 (i) and yshot <= y1 (i) + 30 then
                                targethp (i) := targethp (i) - dmg
                                if targethp (i) <= 0 then
                                    for r : i + 1 .. upper (targethp)
                                        targethp (r - 1) := targethp (r)
                                    end for
                                    new targethp, upper (targethp) - 1
                                    numtarg := numtarg - 1
                                    shoot := false
                                    targets := targets + 1
                                    exit
                                end if
                            end if
                        end for

Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Sun Jun 05, 2011 4:40 pm   Post subject: RE:Could use some help

So is your enemy system like you just throw out a random enemy and every time it dies replace it? Or does it work differently?
CyberStorm




PostPosted: Sun Jun 05, 2011 5:51 pm   Post subject: Re: Could use some help

i throw out a wave of enemies, lets say 5, and when they all get killed, a wave of 6 enemies comes in, and so on. the array gets regenerated after every wave.
DemonWasp




PostPosted: Sun Jun 05, 2011 7:31 pm   Post subject: RE:Could use some help

I can't say for certain, as you've omitted most of your code, but it looks like you're only removing the hit-points entry for the "killed" target, not the entries in the x1 and y1 arrays, which tell the targets where to display. So what's happening is:

- You have three targets: 1, 2, 3.
- You shoot target 2.
- Target 2's hp is "removed", so the HP array contains the hp values for targets [ 1, 3, 3 ], but you've reduced numtarg to 2, so the last value is never seen again.
- However, the x and y value arrays contain data for targets [ 1, 2, 3 ].
- Therefore, when the targets are next drawn, it draws the first two entries, which are targets 1 and 2.
- So it looks like you killed target 3, when really you killed target 2.
Raknarg




PostPosted: Sun Jun 05, 2011 9:24 pm   Post subject: RE:Could use some help

Why do you need to delete the array information? Like how are you showing the enemy health? If you're just putting the number down, you should instead use a health bar:
Turing:

Draw.FillBox (x, y, x + round (100 / maxhp * hp), y + 5)

or something like that.
CyberStorm




PostPosted: Mon Jun 06, 2011 7:31 am   Post subject: Re: Could use some help

DemonWasp solved the actual problem I was having, and thanks Raknarg for the advice.
The only problem left is the "variable has no value" error that pops up occasionally in the for loop that supposed to move values down in the array.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: