Author Topic: Shooting a projectile from middle of screen  (Read 235 times)

Shooting a projectile from middle of screen
« on: 11 Feb 2019, 16:46 »
I have a scrolling room with the mouse locked to the middle of the screen.

I need to have a projectile (Laser Beam) shoot out from the bottom middle of the viewport screen and head toward the target cursor in the middle of the room.

I know the draw command is the best way to do this but I would never be able to figure it out on my own.

So I know another option people use to move projectiles around on the screen is to set an invisible object or character on the screen and then make it visible and move it when needed this is going to have to be the option I take with my level of coding skills.

If this was not a scrolling room I would be able to do this with ease but beings it is a scrolling room how do I get the hidden object to always stay at bottom middle of screen as I am scrolling and being ready to shoot out when needed. Ill be shooting it with the left mouse click.

I also will be needing if it does not collide with another object or character for it to appear as if it is scalling down or getting smaller till it disapears then reset to bottom of room again.


  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: Shooting a projectile from middle of screen
« Reply #1 on: 11 Feb 2019, 17:02 »
The center x coordinate is GetViewportX() + Screen.ViewportWidth / 2

Re: Shooting a projectile from middle of screen
« Reply #2 on: 11 Feb 2019, 22:02 »
I did this in another room that was the default 480x270 game size not scrolling in order to test it out
It is setting a laser beam object in middle of room bottom part of screen  and then moving it though the middle of room on mouse left click.
this works except I need to figure out how to do the part you were helping me with on the finding that middle and keeping it there when the room is scrolling room.

Code: Adventure Game Studio
  2.     if (mouse.IsButtonDown(eMouseLeft) && phaser1_onscreen==false){
  3.        object[0].Visible=true; //laser beam
  4.        object[0].Move(220 , 0, 5, eNoBlock, eAnywhere); //laser beam
  5.        SetTimer(3, 50);  //timer to give laser beam enough time to move off screen
  6.        phaser1_onscreen=true;  //Book to say the laser is on screen
  8. }
  10. else if (mouse.IsButtonDown(eMouseLeft) && phaser1_onscreen==true) {
  12. }
  14. if (IsTimerExpired(3)) {
  15.     object[0].Visible=false; //Hide the laser Laser Beam
  16.     object[0].SetPosition(220, 267); // Reset Laser Beam Location at Bottom
  17.     phaser1_onscreen=false; //reset bool that laser beam is no longer moving on screen
  19. }

This works fine in a non scrolling room now I have to figure out how to edit it to working in the scrolling room with the
instructions you gave me for finding the viewport location.
And I understand what your code means and is supposed to do I am still to dumb to write it out as I still get confused on the whole room vs viewport locations and such.

Code: Adventure Game Studio
  1. center x coordinate is GetViewportX() + Screen.ViewportWidth / 2

But will the code work for what I am looking for.  The way I have it set up if i can get it to hide at the center bottom of the gui overlay I have will work for me to be able to add in all my random, damage, repairs and such and test out a lot of my other stuff and take a big step forward.

« Last Edit: 11 Feb 2019, 22:04 by jamesreg »

Re: Shooting a projectile from middle of screen
« Reply #3 on: 11 Feb 2019, 23:39 »
I started to experiment with the draw commands to see if I could do it

Code: Adventure Game Studio
  1. if (mouse.IsButtonDown(eMouseLeft)) {
  3. DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  4. surface.DrawingColor = 14;
  5. surface.DrawImage(GetViewportX()+236,GetViewportY()+175 , 563, 0, 9, 99);
  6. surface.Release();

I came up with this which I think I need to be using the draw from sprite option instead but I figured out how to get it to draw my laser sprite in the viewport and come shooting up from where I want it to.

So what is the best way to do this to say if it does no collide with the character and disapear off in the distance.
Draw the sprite going to the target cursor, erase it draw a smaller height one erase it and so on?

Will I be able to add collision checks with these drawings?
« Last Edit: 12 Feb 2019, 06:35 by jamesreg »