Shooting a projectile from middle of screen

Started by jamesreg, Mon 11/02/2019 16:46:09

Previous topic - Next topic

jamesreg

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.


Khris

The center x coordinate is GetViewportX() + Screen.ViewportWidth / 2

jamesreg

#2
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: ags
 
    if (mouse.IsButtonDown(eMouseLeft) && phaser1_onscreen==false){
       object[0].Visible=true; //laser beam
       object[0].Move(220 , 0, 5, eNoBlock, eAnywhere); //laser beam
       SetTimer(3, 50);  //timer to give laser beam enough time to move off screen
       phaser1_onscreen=true;  //Book to say the laser is on screen

}

else if (mouse.IsButtonDown(eMouseLeft) && phaser1_onscreen==true) {
 
}

if (IsTimerExpired(3)) {
    object[0].Visible=false; //Hide the laser Laser Beam
    object[0].SetPosition(220, 267); // Reset Laser Beam Location at Bottom
    phaser1_onscreen=false; //reset bool that laser beam is no longer moving on screen
  
}


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: ags
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.


jamesreg

#3
I started to experiment with the draw commands to see if I could do it

Code: ags
if (mouse.IsButtonDown(eMouseLeft)) {

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawImage(GetViewportX()+236,GetViewportY()+175 , 563, 0, 9, 99);
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?

SMF spam blocked by CleanTalk