?
Solved

Need help with tag type delphi game

Posted on 2003-02-19
15
Medium Priority
?
161 Views
Last Modified: 2010-04-04
i got both my character to move around the screen(there is no AI just a 2 pplayer game) i need it so when my image1 goes on image2. label1 says hit and then my score section will say 1
0
Comment
Question by:karatekid183
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 

Expert Comment

by:NightAwk
ID: 7983714
Well first of all i'll asume u have a timer, if not then
u'll need one, to make image1 move toward image2.

anyway in the timer, simply detect collision w this fucntion :

function Form1.Hit : Boolean ;
begin
  Hit := False ;

  (* this function check if image1 is overlaping image2 *)
  if (image1.Left+image1.Width >= image2.Left)
  and (image1.Left <= image2.Left+image2.Width)
  and (image1.Top+image1.Height >= image2.Top)
  and (image1.Top <= image2.Top+image2.Height) then
    Hit := True ;
end ;

set the timer interval to 1000 and every timer call, move ur image1 a lil bit more in the direction its going, so u will get a smooth animation. And call Hit eachtime, if it returns true, set ur label and score caption.

this fonction works only check for 4 axis, if u plan
to use diagonals too, then u would have to change the hit function a lil bit i think.

Good luck.
0
 

Author Comment

by:karatekid183
ID: 7983867
actually i dont have a time, all i have right now is both of my character are able to move round the screen(by P1 using the arrows and P2 using w,a,s,d) so what do i have to put in my timers and what does form1.hit:boolean mean
0
 
LVL 1

Expert Comment

by:User137
ID: 7985971
There is no need for timer if there's nothing moving without user pressing keys.

Let's make it simple:

If your form's name is Form1, then Replace erroreous line:

function Form1.Hit: Boolean;
with
function TForm1.Hit: Boolean;

Then after the key handling code put these:

if Hit then begin

Label1.Caption := 'Hit';

end else begin

// What exactly must be done when player scores,
// comes here

end;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:karatekid183
ID: 7987927
Where do i put function TForm1.Hit: Boolean??
0
 

Author Comment

by:karatekid183
ID: 7987952
Where do i put function TForm1.Hit: Boolean??
0
 

Author Comment

by:karatekid183
ID: 7988014
where do i put TForm1.Hit: Boolean
0
 

Author Comment

by:karatekid183
ID: 7988017
where do i put TForm1.Hit: Boolean
0
 

Expert Comment

by:NightAwk
ID: 7988649
u put the interface of the function here :


  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    function Hit : boolean ;
  public
    { Public declarations }
  end;

and u put the function itself where ever u like in the unit.

if ur goal is to only detect if the two players are touching each other, then yeah u dont need a timer,
i was thinking you were like usign projectile, like a gun
fighting game, then u would need a timer to make the projectile move. but that not the case so forget about timers.

jsut call hit everytime a player moves his character.

the function should work in theory, u may have to change variables names and all.

good luck.

P.S. maybe learning a lil bit more about delphi and apscal wouldn't hurt you, u know ..  anyone woudl had known that bye creating a Tform1.hit fucntino u would have to put the declaration in the Tform1 class...
0
 

Expert Comment

by:NightAwk
ID: 7988652
u put the interface of the function here :


  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    function Hit : boolean ;
  public
    { Public declarations }
  end;

and u put the function itself where ever u like in the unit.

if ur goal is to only detect if the two players are touching each other, then yeah u dont need a timer,
i was thinking you were like usign projectile, like a gun
fighting game, then u would need a timer to make the projectile move. but that not the case so forget about timers.

jsut call hit everytime a player moves his character.

the function should work in theory, u may have to change variables names and all.

good luck.

P.S. maybe learning a lil bit more about delphi and pascal wouldn't hurt you, u know ..  anyone woudl had known that bye creating a Tform1.hit fucntino u would have to put the declaration in the Tform1 class...
0
 

Expert Comment

by:NightAwk
ID: 7988669
u put the interface of the function here :


  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    function Hit : boolean ;
  public
    { Public declarations }
  end;

and u put the function itself where ever u like in the unit.

if ur goal is to only detect if the two players are touching each other, then yeah u dont need a timer,
i was thinking you were like usign projectile, like a gun
fighting game, then u would need a timer to make the projectile move. but that not the case so forget about timers.

jsut call hit everytime a player moves his character.

the function should work in theory, u may have to change variables names and all.

good luck.

P.S. maybe learning a lil bit more about delphi and pascal wouldn't hurt you, u know ..  anyone would had known that by creating a Tform1.hit function u would have had to put the declaration in the Tform1 class...
0
 

Author Comment

by:karatekid183
ID: 7989436
ok this is what i put:
 TForm1 = class(TForm)
    Image2: TImage;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    MainMenu1: TMainMenu;
    Ouvrir1: TMenuItem;
    Nouveaux1: TMenuItem;
    Fermer1: TMenuItem;
     
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Fermer1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Déclarations privées}
  public
    { Déclarations publiques}
  end;

when i place private
   function Hit : boolean ;
 public
   { Public declarations }
 end;
 it give me like 10 errows bout procedure FormKeyDown. whats wrong, do i declare hit has a variable? also how would i place walls? BTW IM NOT A NOOB, IM IN 11TH GRADE PROGRAMMING, I KNOW HOW TO USE, FOR, CASE, IF AND OTHER STUFF
0
 

Accepted Solution

by:
NightAwk earned 80 total points
ID: 7991028
well then jsut forget about form1.hit and just declare "function Hit : boolean", put the function in the top of the unit so other functions will be able to call it.

well u might know alot about for and while and all, but knowing more about objects and classes would help u, thats all i wanted to say.

good luck.
0
 

Expert Comment

by:CleanupPing
ID: 9317182
karatekid183:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 10

Expert Comment

by:kacor
ID: 9928068
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       the answers contains useful information, it would be mistake to delete,
       but the original question is not solved
       to accept xx's answer
       to split points between xx and xx
       to delete this answer and refund points
       PAQ and refund points
       to delete this question and give points to xx
       to delete this question and NOT refund points
       this question don't belong to this topic, otherwise don't contain useful information
       the question to be moved into xxxx topic
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup VolunteerNo comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to accept NightAwk's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question