offsetting objects

BlitzMax Forums/BlitzMax Programming/offsetting objects

Eikon(Posted 2005) [#1]
This is probably a stupid question, but I am really terrible with math and haven't been able to figure this out. I am writing a side scrolling game that needs to offset objects with scrolling. When a player shoots a bullet that uses sin/cos for an angled shot, how would I go about moving this bullet backwards as the player runs forward? I've tried changing the X, Y origin, but this changes the whole path of the bullet.

Here is example code (not bmax because im lazy)
Graphics 640, 480, 16, 2
SetBuffer BackBuffer()

A = 290: R = 0
X = 320: Y = 240

While Not KeyDown(1)

Rect R * Cos(A) + X, R * Sin(A) + Y, 4, 4
R = R + 3
;X = X - 1

Flip:Cls
Wend:End
If you uncomment the X line, the bullet path changes instead of moving backwards while still traveling at the same angle. How do I accomplish this?


LarsG(Posted 2005) [#2]
shouldn't changing the origin (as to where you are in the world, and what you draw) handle this?

what I mean is that both the player and the bullet has it's own x,y coordinate which are updated each frame (or so).
you just let them do their own calculations, then when you're drawing the screen, you center the screen around the player coord with the origin command(or some other word coordinate, if you use that)..


Eikon(Posted 2005) [#3]
* edit *
Trying now, I'll let you know how it goes.

The problem is, my player position doesn't really change once scrolling begins, it stays centered on screen and the map moves around him, so each bullet fired will start at the same position. Is there an easier way to do this than setting an origin for both the bullet and the player?


Eikon(Posted 2005) [#4]
Please help me out here, I'm still stuck on this. When the player reaches the center on the screen (the point where map scrolling begins), how can I have the bullet move backward as you move forward, and still keep the player centered?

Graphics 640, 480, 16, 2
SetBuffer BackBuffer()

A = 290: R = 0

PX = 20: PY = 260
While Not KeyDown(1)

Origin X, Y
Rect R * Cos(A), R * Sin(A), 4, 4
R = R + 3

Origin PX, PY
Rect 0, 0, 4, 4

If KeyDown(205) Then
	If PX < 320 Then PX = PX + 1 Else PX = 320
EndIf

If KeyDown(203) Then PX = PX - 1

If KeyHit(57) Then A = 290: R = 0: X = PX + OX: Y = PY

Flip:Cls
Wend:End
Use left/right to move and space to shoot.


tonyg(Posted 2005) [#5]
I don't know what you're asking. The result looks alright.


Eikon(Posted 2005) [#6]
OK, I'll try to explain better.

When the player reaches the center of the screen, map scrolling begins. This means the player appears to be moving forward, even though he is still at the same position (320).

In the current code example, the bullet originates from the center point of the screen and remains there, even when you continue to hold right. My question is, once centered, how do I get the bullet to move backward as you hold right, while still keeping the player at the same screen position.


Rimmsy(Posted 2005) [#7]
This is a quick hack:
Man, I am *not* used to blitz3d again after using bmx for a long while. This should do what you want. You're bascally offsetting the drawing not the position. See the code.




Eikon(Posted 2005) [#8]
Awesome. Thanks much, Rimmsy.


Rimmsy(Posted 2005) [#9]
No problem. That code ^^^ is a bit of a shoddy version but you should be able to get the gist of it.