SCR Move - SinCosRadMove

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

SCR Move - SinCosRadMove

Post by Nixola »

I read this post, and I wanted to try to do something like that. So, in ~2½ hours, I coded this. My code is a mess ( I don't like love.update() ), and graphics are even worse, but it works.
In the top-left corner I put an HP bar (just in case I go on with this... thing) and a fuel bar, that replenish itself while standing still. Spacebar decreases HP by 10 and fuel by 90%, and ↓ set both to 100%.
EDIT: I missed a 0 (so ↓ only set fuel to 10%) and forgot to change window's title
Attachments
SinCosRadMove.love
(2.98 KiB) Downloaded 237 times
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: SCR Move - SinCosRadMove

Post by Robin »

Nice.

Here's an exercise for you: it looks a bit like Astroid at this point. Only in space there is no friction: if there is no force working on an object it just goes on in the same direction forever. To stop or change direction, you'll need to turn and accelerate the other way. See if you can implement this.
Help us help you: attach a .love.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: SCR Move - SinCosRadMove

Post by Nixola »

I improved a bit SCR Move while you were writing your post (added small deceleration and a speedometer), when I read it I wanted to go to sleep (00:40 AM in Italy). Now I've gotta go, after lunch I'll try to implement that.
P.S: I wrote "coming soon" 'cause I didn't understand how to code the speedometer (I told you, it was late :oops: ), and when I understood it I didn't have the time to cancel the writing.
EDIT: forgot the attachment
EDIT: too many of them :shock:
Attachments
SinCosRadMove.love
(28.4 KiB) Downloaded 164 times
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
hughes
Prole
Posts: 21
Joined: Fri Oct 28, 2011 3:10 am

Re: SCR Move - SinCosRadMove

Post by hughes »

Neat! Looks good so far.

You probably noticed things don't look quite right when turning at high speeds. If you're going for an asteroids-feel where you drift along and rotate freely without turning like an airplane, you'll want the thrust to control acceleration instead of velocity.

What I mean is...

Code: Select all

in love.load
  vx = 0
  vy = 0
  thrust = 10 (or some appropriate number)
end

in love.update
  fx = 0 -- horizontal force
  fy = 0 -- vertical force
  if up key is pressed
    -- rocket is firing, apply thrust
    fx = fx + thrust*math.cos(angle)
    fy = fy + thrust*math.sin(angle)
  end
  -- the thrust only modifies the velocity
  vx = vx + fx*dt
  vy = vy + fy*dt
  -- now the resulting velocity modifies the position
  x = x + vx*dt
  y = y + vy*dt
end
Try this and you'll find that using forces in addition to storing the velocity makes for much more realistic motion.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: SCR Move - SinCosRadMove

Post by Nixola »

I was thinking about something like that... Thank you ^^
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: SCR Move - SinCosRadMove

Post by josefnpat »

This is very very smooth, nice job!

May I suggest you round the percentage below the health bar and the speed on the spedometer

Also, alias the the throttle image (the thing that shows how fast you're going).


:)
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: SCR Move - SinCosRadMove

Post by coffee »

Nixola, good work in engine but I have the feeling that you are using the wrong anchor point to rotate your ship (or you are not updating well that point). The rotation of the ship don't feel natural and ship isn't really rotating but like circle outside-facing around one point at the back of the ship. Or you really wish a rotation like this?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: SCR Move - SinCosRadMove

Post by Nixola »

The point is the center of the ship (ship: 32x32px, offset: 16, 16), now II'm working on this post, I rewrited everything and controlled it at least 15 times, but I can't make the ship move like this :?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: SCR Move - SinCosRadMove

Post by Nixola »

After 3 days hunting an error, I found a "math.sin" instead of a "math.cos" ( :x ), I named this new version "SCR Asteroids", even if there aren't asteroids (for now). I'll draw a better ship (maype :P ) and implement enemies spaceships. Until then, don't press spacebar. DON'T.
Attachments
SCR Asteroids.love
(28.78 KiB) Downloaded 177 times
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
hughes
Prole
Posts: 21
Joined: Fri Oct 28, 2011 3:10 am

Re: SCR Move - SinCosRadMove

Post by hughes »

Sweet! You've got it! That type of motion works really well and has a very spacey feel.
Post Reply

Who is online

Users browsing this forum: No registered users and 74 guests