RawDraw on Sprites + Verb Coin Issues (SOLVED)

Started by TheJBurger, Tue 29/01/2008 00:46:38

Previous topic - Next topic

TheJBurger

Ok, so here's the deal:
You press space to shoot at a target. I want there to be a random bullet hole placed on the target after firing. Here is my code so far:
Code: ags

// press space to fire
 else if (keycode == 32 && position == 1) { // space to shoot when out of cover
  player.LockView(6); // gun shoot
  player.Animate(0, 5, eOnce, eBlock, eForwards); // fire!
  breath=0; // kill breath.
  sldrShift.Value=breath;
  btnFlash.NormalGraphic=22;
  if (headshot == 0) 
  { // not charging.
  //int shotx=oTarget1.X+Random(11);
  //int shoty=oTarget1.Y-Random(39);

   int shotx=oTarget1.X-GetViewportX()+Random(11); // coordinates for bullet
   int shoty=oTarget1.Y-GetViewportY()-Random(39); // width and height of sprite
  if (Object.GetAtScreenXY(shotx, shoty) == oTarget1) { // if random coordinates are on target.
  // code here
  DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(oTarget1.Graphic);
  DrawingSurface *surface = sprite.GetDrawingSurface();
  surface.DrawingColor = 8322;
  surface.DrawPixel(shotx, shoty); // draw a pixel bullet hole.
  Display("hit!"); // check if it works. it does.
  surface.Release();
  oTarget1.Graphic = sprite.Graphic; // turns into a blue cup instead of a bullet induced target.
  }
}


shotx, and shoty will store the coordinates of the bullet I will draw. The image of the target is 11 x 39. This is a scrolling room so I went out on a limb to use getviewportx() and Y to set the object's position straight. I wasn't sure about this since I didn't know if Object.GetAtScreenXY was taking screen or room coordinates, and the same for Object.X. Either way, the code works since I got "hit!" to display.

My problem is that I don't know how to get RawDraw working on the target to create the bullet hole. I tried using rawdraw on the background, but that didn't appear to work and I thought it was because the object was covering it up. So, I tried to create a dynamic sprite to do the work but now it just turns my object into a blue cup.

Shane 'ProgZmax' Stevens

rawdraw can't currently draw over sprites (characters/objects).  It's something I've suggested, since it would be nice to be able to do this without cutting out a dynamic sprite and turning it into an overlay, which is an additional (and imo unnecessary) step, but you can do it that way.  Most of the rain modules do the same thing with groups of sprites on graphic overlays.

Khris

First of all, Object.GetAtScreenXY uses... screen coordinates!
Quote from: manualChecks if there is a room object at SCREEN co-ordinates (X,Y). Returns the object if there is, or null if there is not.

Progz, this isn't an attempt to RawDraw over an object.

TheJBurger, you need to use a global DynamicSprite. Declare it outside the on_key_press function. Right now, AGS gets rid of the DynamicSprite as soon as on_key_press finishes because it's local to the function, resulting in the blue cup showing as the target's sprite.

If I may again quote the manual:
QuoteIMPORTANT: If the DynamicSprite instance is released from memory (ie. there is no longer a DynamicSprite* variable pointing to it), then the sprite will also be removed from memory. Make sure that you keep a global variable pointer to the sprite until you are finished with it, and at that point call Delete.

TheJBurger

Quote from: KhrisMUC on Tue 29/01/2008 01:42:54
TheJBurger, you need to use a global DynamicSprite. Declare it outside the on_key_press function. Right now, AGS gets rid of the DynamicSprite as soon as on_key_press finishes because it's local to the function, resulting in the blue cup showing as the target's sprite.

Mmm... I declared my two Drawing functions at the top of my room script:
Code: ags

DynamicSprite *sprite; 
DrawingSurface *surface;


I changed the old code to this:
Code: ags

if (Object.GetAtScreenXY(shotx, shoty) == oTarget1) { // if random coordinates are on target.
  // code here
  sprite = DynamicSprite.CreateFromExistingSprite(oTarget1.Graphic);
  surface = sprite.GetDrawingSurface();
  surface.DrawingColor = 8322;
  surface.DrawPixel(shotx, shoty); // draw a pixel bullet hole.
  Display("hit!"); // check if it works. it does.
  surface.Release();
  oTarget1.Graphic = sprite.Graphic; // turns into a blue cup instead of a bullet induced target.
  }


The first time it runs, the blue cup doesn't appear, but neither does the bullet hole. The second time the script is run, the blue cup appears right before "hit!" and disappears right after it, with still no change in the target.

Khris

I don't know why the blue cup keeps appearing, I'm about to test the code.
One thing I've noticed, though:
shotx/y are screen coordinates.
But drawing on the object's drawing surface has its origin at the object's top left corner.
So you have to draw @ shotx-object.x / shoty-object.y

TheJBurger

I think I fixed it.

Here's the code I used.
Code: ags

 sprite = DynamicSprite.CreateFromExistingSprite(oTarget1.Graphic);
  surface = sprite.GetDrawingSurface();
  surface.DrawingColor = 10434;
  int shot2x=Random(11);
  int shot2y=Random(39);
  if (Object.GetAtScreenXY(shot2x+oTarget1.X-GetViewportX(), shot2y+oTarget1.Y-39) == oTarget1) {
  surface.DrawPixel(0+shot2x, 0+shot2y); // draw a pixel bullet hole.
 // Display("hit!"); // check if it works. it does.
}

I just stopped using Display and that also stopped the blue cup nonsense. The bullet holes appear fine.

On a completely different related note, I have another problem.

I'm trying to make a 7Days-esque verb coin, and I got it working so far, but the inventory is not working for me. I tried different stuff but I can't get it to work. I have "Handle Inventory Clicks" enabled.
Code: ags

 else if (button == eMouseLeftInv) {
    InventoryItem*ia=inventory[game.inv_activated]; // use inventory
    player.ActiveInventory=ia;
    ProcessClick(mousex, mousey, eModeUseinv); // mousex, mousey are the coordinates of the previous mous click.
  }
  else if (button == eMouseRightInv) {
    inventory[game.inv_activated].RunInteraction(eModeLookat);
    }


I checked the "`" console to see what was going on and all it says is "Mouse Click Over GUI 5."

Khris

Did you change the inventory GUI visibility to "Normal" instead of "Popup modal"?

TheJBurger

Quote from: KhrisMUC on Wed 30/01/2008 18:04:05
Did you change the inventory GUI visibility to "Normal" instead of "Popup modal"?

Thank you, that did it. However, is there any way to have that GUI on and have the game paused?

Khris

You can set the GUI back to Popup modal, then rewrite on_mouse_click so that LeftInv/RightInv are processed even though the game is paused.

Alternatively, make the GUI disappear as soon as the mouse leaves it.


SMF spam blocked by CleanTalk