Jump to content

Photo

some movement code

Bresenham movement

30 replies to this topic

#26 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Space Invader

  • 40 posts

Posted Tue Nov 14, 2017 12:22 AM

I made an example of what I want to do, I have robots in my game that shoots missiles at you, but they can only shoot in six directions now and I would like if they shot in the exact direction you where when they fired the shot, I can do that but the problem is that the robots slowly speed up with 0.05 every one hundred points, and the missile automaticly speeds up to, 

the missilespeed is the robotspeed + 0.10

So it would just be for speed flexibility, and the smoothness ofcourse, subpixel bresenham movement seems impossible in my brain but I thought I should ask,

what do you think?

Attached File  StraightLine.bas   10.71KB   7 downloads


Edited by Lillapojkenpćön, Tue Nov 14, 2017 1:16 AM.


#27 Mountain King OFFLINE  

Mountain King

    Dragonstomper

  • 618 posts
  • Location:Philadelphia, PA

Posted Wed Nov 15, 2017 5:18 AM

Bogox,

How would you handle 3 moving objects?

Player moves a cursor, 

first object moves to that cursor when activated.

Second object follows and tries to catch the first object.



#28 bogax OFFLINE  

bogax

    Dragonstomper

  • Topic Starter
  • 718 posts

Posted Wed Nov 15, 2017 5:44 PM

I made an example of what I want to do, I have robots in my game that shoots missiles at you, but they can only shoot in six directions now and I would like if they shot in the exact direction you where when they fired the shot, I can do that but the problem is that the robots slowly speed up with 0.05 every one hundred points, and the missile automaticly speeds up to, 

the missilespeed is the robotspeed + 0.10

So it would just be for speed flexibility, and the smoothness ofcourse, subpixel bresenham movement seems impossible in my brain but I thought I should ask,

what do you think?

attachicon.gifStraightLine.bas

 

 
The movement code always moves one pixel
 
The first thing I'd try is set up an accumulator for the fractional change of
position and when it's accumulated a pixel's worth do the movement
 
something like
 
 
  temp = accumulator
 
  accumulator = accumulator + speed
 
  if accumulator < temp then skip_move
 
  movement code
 
skip_move
 


#29 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Space Invader

  • 40 posts

Posted Thu Nov 16, 2017 8:58 PM

Seems like I don't have to? I have no idea how it works without setting the error accumulator and all the other stuff?

Attached File  _Chase.bas   3.67KB   6 downloads

Attached File  _NoChase.bas   3.9KB   7 downloads



#30 bogax OFFLINE  

bogax

    Dragonstomper

  • Topic Starter
  • 718 posts

Posted Sat Nov 18, 2017 8:18 AM

Seems like I don't have to? I have no idea how it works without setting the error accumulator and all the other stuff?

attachicon.gif_Chase.bas

attachicon.gif_NoChase.bas

 

 
 I'm not sure what you're asking
 
 You're setting all the important stuff
 
 You don't neccesarily need to set the error accumulator
 it just makes nicer lines (I think)
 
 You count through the delta in the error accumulator until it rolls over
 at which point you've accumulated a pixel worth of error so you move one
 pixel in the minor direction
 If you set the error accumulator to 1/2 the delta you're half a pixel
 from where you want to be on the line and you can only be at whole pixels
 If you set the error accumulator to 0 you'd be at one pixel from where
 you want to be and the first thing you'd do is take a step in the minor
 direction
 
 The line is formed from horizontal or vertical line segments in the major
 direction
 
 Say the segment is going to be 8 pixels ie you'll move 8 pixels in the major
 direction to accumulate one pixel of error in the minor direction
 (the error accumulator counts down through the major delta in minor direction
 deltas until it goes through zero) if you set the error accumulator to
 0 you're one pixel away and you'll immediately take a step in the minor direction
 If you set the error accumulator to 1/2 the major delta you'll take four steps
 (half of 8 )  before you take a step in the minor direction
 and if you set EA to the major delta you'll take 8 steps before you've
 accumulated enough error for a step in the minor direction 
 
 something like this for a 9 pixel line
 
 _
  ________
 
 ____
     _____
 
 ________
         _
 
 
 
 as far as multiplying by 2 if you're working with numbers below 128
 that just gives you a little more room for accuracy if you're going
 to do something else with the error accumulator (since you're continuously
 bending the line perhaps you'd want to take into account where you are
 on the previous line) but it's really not neccesary (or even useful if
 you're just setting the error accumulator to eg 1/2 the delta) 

Edited by bogax, Sat Nov 18, 2017 8:19 AM.


#31 bogax OFFLINE  

bogax

    Dragonstomper

  • Topic Starter
  • 718 posts

Posted Sat Nov 18, 2017 8:38 AM

Bogox,

How would you handle 3 moving objects?

Player moves a cursor, 

first object moves to that cursor when activated.

Second object follows and tries to catch the first object.

 

 
 I'm not sure I know what you're asking
 
 Simplest would be to have variables and
 movement code for each object that needed it and reset up
 an object whenever a its target changed position
 
 However you might end up doing more setup than you needed
 depending on how they're moving relative to one another
 
 You could parameterize and reuse the same code for different objects
 not sure it would be worth it unless you had a lot of objects 





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users