OLPCities/Shooting in the bad guys: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:




Look the figure. The astronaut has a gun. And glued to the gaun there are a little red bullet. They are in the "Pink planet" and the astronaut can shoot against one of the "echoos", the mosters that live in the planet.
Look the figure. The astronaut has a gun. And glued to the gun there are a little red bullet. They are in the "Pink planet" and the astronaut can shoot against one of the "echoos", the mosters that live in the planet.


How did we code this?
How did we code this?

Revision as of 17:40, 24 September 2006

Tut7-1.jpg


Look the figure. The astronaut has a gun. And glued to the gun there are a little red bullet. They are in the "Pink planet" and the astronaut can shoot against one of the "echoos", the mosters that live in the planet.

How did we code this?

The sprite "bullet" needs to be "glued" to the sprite "astronaut" aproximately near the gun and having an inferior "Z" to be hided. There are the method follow to do it. At the exercice we have:



 
bl.follow(av,15,   16);

The two number are de coordinates of the bullet "inside" the avatar. At the moment of the shoot (pressing the key "P") we liberate the bullet, difine its direction (the same of the avatar at this moment) and we increase the velocity (2 for the avatar and 5 for the bullet)> Look part of the code. This action needs to be "discreet" - only one time - and we use a flag ("shoot") to define it.:

...
if(skey.pressed){
 if(shoot==0){
   bl.stopFollowing();
   bl.setDir(av.xdir,av.ydir);
   bl.setSpeed(5);
   shoot=1; 
  }
...