6 Months Free & No Setup Fees ASP.NET Hosting!
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » .NET General » Picking up the sword
       
Author Reply
albert albert
posted 151 posts
since Dec 02, 2008 
from

Picking up the sword

  Posted on: 09 Feb 2012       
I am now bussy with picking up the sword.

the player picks up the sword and the picture will be shown in the inventory and the picture of the sword u picked up will be invisible. and u see the pictuce of the player with the sword in the dungeon.

I have this method:

[code]
 public Point Move(Direction direction)
  {
  string weapon;
  base.location = Move(direction, game.Boundaries,location);
 
 
  if (!game.weaponInRoom.PickedUp)
  {
  //rest of the logic. 

  if (equippedweapon.Nearby(location,1))
  {
  equippedweapon.PickedUP();
  //if (equippedweapon.PickedUP() == game.CheckPlayerInventory(equippedweapon.Name) )
  //{ 
  //}
  //else
  inventory.Add(equippedweapon);
  if (weapons.Contains(1))
  {
 
  }
  }
  }
 
  return location;
 
 
 
  }//end method
[code]
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: picking up the sword
  Posted on: 09 Feb 2012        0  
I have an update:

[code]

        public Point Move(Direction direction)
        {
          
            string weapon;
            base.location = Move(direction, game.Boundaries,location);
           
           
            if (!game.weaponInRoom.PickedUp)
            {
                //rest of the logic.  
                if (game.weaponInRoom.Nearby(this.Location, this.distance) == true)
                {
                    equippedweapon.PickedUP();
                    inventory.Add(equippedweapon);                   
                }
                //if (this.game.weaponInRoom.Nearby(location,distance) == true)
               // {
                   
               // }
              
            }
             
            return location;      
        }//end method
[/code]
Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: picking up the sword
  Posted on: 09 Feb 2012        0  
I loaded your project and am getting errors
Check your code and upload project again
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: picking up the sword
  Posted on: 09 Feb 2012        0  
here is the project so far.
Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: picking up the sword
  Posted on: 09 Feb 2012        0  
Whats the question ?
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: picking up the sword
  Posted on: 09 Feb 2012        0  
this method:

[code]

public Point Move(Direction direction)
  {
 string weapon;
  base.location = Move(direction, game.Boundaries,location); 
 
  if (!game.weaponInRoom.PickedUp)
  {
  //rest of the logic. 
  if (game.weaponInRoom.Nearby(this.Location, this.distance) == true)
  {
  equippedweapon.PickedUP();
  inventory.Add(equippedweapon); 
  }
 
  }
 
  return location; 
  }//end method

[/code]

in the Player class.

The player moves to the weapon(sword) and the the sword will dissapear in the dungeon, where the player moves and appears in the inventory and also the player with the sword will appear. But now the situation is if  u press on a move button the action is already done before the player pickedup the weapon.
Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: picking up the sword
  Posted on: 09 Feb 2012        0  
You will have to check if player picbox intersects with sword picbox before picking up the sword
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: picking up the sword
  Posted on: 09 Feb 2012        0  
yes . But how to do that in the Player class?

I think in the form class it is already done, isnt?


albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: picking up the sword
  Posted on: 09 Feb 2012        0  
I pputted this in the from class:

[code]
public void intersects()
        {
            Rectangle p1 = this.pcPlayer.ClientRectangle;
            p1.Offset(this.pcPlayer.Location);

            Rectangle p2 = this.pcSword.ClientRectangle;
            p2.Offset(this.pcSword.Location);

            bool overlapped = p1.IntersectsWith(p2);
[/code]
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: Picking up the sword
  Posted on: 10 Feb 2012        0  
Iv made an update. But still the Player and the Weapon intersects with eatch other before they realy intersects with eatch other

And I dont understand why the pcSword not dissapear from the Dungeon, because I set the property vissible to false.
Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: Picking up the sword
  Posted on: 10 Feb 2012        0  
Try this
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: Picking up the sword
  Posted on: 10 Feb 2012        0  
Eh, u have sent me the same version Iv sent u
Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: Picking up the sword
  Posted on: 10 Feb 2012        0  
No -run it
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: Picking up the sword
  Posted on: 11 Feb 2012        0  
I am sorry.

u changed this method:
And the Form class.
[code]
 public Point Move(Direction direction)
  {
  //Rectangle r1 = new Rectangle(new Point(this.Location.X, this.location.Y),this.width,this,heigt);

  //Point target = equippedweapon.Location;
  string weapon;
  base.location = Move(direction, game.Boundaries,location); 
 
 
  return location; 
  }//end method
[/code]

But If u put a breakpoint on this line in the form Class:

  weaponControl.Location = game.weaponInRoom.Location;
  if (game.weaponInRoom.PickedUp)  --- u can put a breakpoint on this line, then it will be executed befor the player actually hit with the sword.  
  weaponControl.Visible = false; 

That I dont understand. Because only when the player hits with the the sword then the weapon in the dungeon will be removed and the sword in the inventory will be showed. That is how it has to be.  

albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: Picking up the sword
  Posted on: 11 Feb 2012        0  
Iv made an update, but still the sword stays visible in the Dungeon, when the player picks up the sword.

And still the form doesnt communicate with the player method

And when I put a breakpoint on this lines:

Form class:
[code]
  weaponControl.Location = game.weaponInRoom.Location;
  if (game.weaponInRoom.PickedUp) 
  weaponControl.Visible = false; 
[/code]

the code is executed before the player picked up the sword.

this function:
[code]
 weaponControl.Location = game.weaponInRoom.Location;
  if (game.weaponInRoom.PickedUp) 
  weaponControl.Visible = false; 
 
  else 
  weaponControl.Visible = true;
[/code]
 is necessary because this doesnt working ofcourse:
[code]
 case "Sword":
  weaponControl = pcSword;
  locationWeapon.Text = weaponControl.Location.ToString();
  if (intersects() == true)
  {
  //weaponControl.Visible = false;
  pcSword.Visible = false;
  inventorySword.Visible = true;
  inventorySword.BorderStyle = BorderStyle.FixedSingle;
  pcPlayerSword.Location = weaponControl.Location;//That the new image is show on the place where the player pickedup his weapon!!
  pcPlayerSword.Visible = true; 
  pcPlayer.Visible = false;
  //if (inventorySword.Visible = true)
  //  weaponControl.Visible = false;
 
 
  }
  break;
[/code]


because then only the sword is !visible when the player intersects with the sword. but after the interseciton the sword is still visible.
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: Picking up the sword
  Posted on: 11 Feb 2012        0  
And there is also something strange:

[code]
 public bool checkForWeapon(Rectangle playRect, Rectangle weaponRect)
  {
  bool isPickup = false;
  if (playRect.IntersectsWith(weaponRect))
  {
  isPickup = true;
  }
  return isPickup;
  }
[/code]

I putted an breakpoint on this line: isPickup = true;

but when the player intersects with the sword the variable isPickup says: false. strange
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: Picking up the sword
  Posted on: 12 Feb 2012        0  
I have it now likes this:

[code]
class Weapon
public bool PickedUP(bool pickedUp)
  {
  if (pickedUp == true) 
  return true;  //I putted here an breakpoint and it gives true when the player intersects with the sword. So that is good  
  else
  return false;
  //pickedUp = true;
  return pickedUp;
  }
[/code]

but if I put here an breakpoint:

[code]
class Form
 weaponControl.Visible = true;

  weaponControl.Location = game.weaponInRoom.Location;
  if (pickUpWeapon = game.weaponInRoom.PickedUp)
  //if(( pickUpWeapon = game.checkForWeapon(pcPlayer.Bounds, pcSword.Bounds)) == true)
  //if( game.weaponInRoom.PickedUP(pickUpWeapon) == true)
  {
  //game.MovePlayer(direction, boundaries, location);
  // pickUpWeapon = game.checkForWeapon(pcPlayer.Bounds, pcSword.Bounds);
  lb_pickedupSword.Text = game.weaponInRoom.PickedUP(pickUpWeapon).ToString();
  --->   weaponControl.Visible = false;// here I putted an breakpoint , but nothing happens
  //so u have to guess where the sword is and the the sword will be shown in the
  //inventory
  }
  else
  {
  weaponControl.Visible = true;
  }
[/code]
Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: Picking up the sword
  Posted on: 12 Feb 2012        0  
When i ran your code - right move - I put a breakpoint on the first item in MoveRight_Click
Pressing F11, I did a count of code lines - I stopped at 300 and it still had not finished the method
You move from class to class like a bouncing bullet - and all the methods do is transfer to another class - virtually popping to say hello and doing nothing constructive

My advice- Restart the project and make it simple
Form1 handles imputs and graphics
Game class is the game engine
weapon class holds only info on weapons
enemy class holds only info on enemies
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: Picking up the sword
  Posted on: 12 Feb 2012        0  
I think u are right. But it is logical that there is a Abstract class Enemy, because u have several enemies and an abstract class: Weapon, because u have several weapons,isnt?
Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: Picking up the sword
  Posted on: 12 Feb 2012        0  
The weapon abstract class is a base class - and as the weapons -sword mace etc have same methods it is a good idea to use abstract class.
You have a mover abstact class which may be ok for enemies, but not in my opinion for the player.

When you create a project (after you have outlined what your program will do), do one thing at a time ie create player and movement.
When you add enemies or weapons further down the track- keep testing to ensure your later code has not interfered with your player
Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: Picking up the sword
  Posted on: 12 Feb 2012        0  
very simple example
albert albert
posted  151 posts
since  Dec 02, 2008 
from 

 Re: Picking up the sword
  Posted on: 12 Feb 2012        0  
THX
       
Team Foundation Server Hosting
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved