Advertisement

Shooter game in development but need some help in early stages!

Started by July 22, 2002 06:17 PM
1 comment, last by Serenic 22 years, 4 months ago
I am currently doing a point and click shooting game using delphi 5 for school and I am just starting it but already have a problem. I want it so that each time you click anywhere in the screen your shots go up by 1, so its just counting how many shots you have done. So far I have gotten the code so that it goes from 0 to 1 but then it won''t count any higher, it just stays on one. Here''s the code: procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var Shots: integer; begin Shots:= 0; Shots:= Shots+1; Shot.caption:= (''Shots: '' + IntToStr(shots)); end; I think the problem here is when it counts to one it goes back to zero and counts to one again every click because of the Shots:=0; Can somebody please help me with this, all is appreciated!!! Thanks ()<>()<>()<>()<>()<>()<>()<>()
()<>()<>()<>()<>()<>()<>()<>()
Think about what happens whenever you press the button. You''re always resetting the value to 0 and then incrementing it. Say I passed in any value whatsoever for the number of shots... let''s say 29. The first line of code resets that to zero.

Shots := 0;
Shots := Shots + 1;

is equivalent to
Shots := (0) + 1; // shots := 1;

...which will always be one . The solution is simple enough: move your line of code that sets shots to 0 somewhere else where it will not be called each click. Perhaps in the section that creates a new game or something. The important thing is that it only gets called *once* per game to clear the score.
Advertisement
Looks like a For Beginners topic.

*Thread moved*

--------------------
Just waiting for the mothership...
--------------------Just waiting for the mothership...

This topic is closed to new replies.

Advertisement