Author Topic: Parallax  (Read 2234 times)

johnno56

  • Guest
Parallax
« on: June 26, 2015 »
I made a Flappy Bird clone a while back using sdlbasic and wanted to see if I could simulate a 'parallax effect' using Naalaa. This is only part of the game. It is purely for effect and cannot be played. Can someone check the code to see if I have at least done something right? The 'movement' seems to be slightly jerky.

I would appreciate any advice in regards to any improvements.

J

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Parallax
« Reply #1 on: June 26, 2015 »
Hi J,

I just checked out your code. The vertical height is just a bit too much for my screen. I suppose all the action will be taking place in sky as it is 2/3's of screen. (I am unfamiliar with Flappy Bird.)

For perspective effect, the more distant the object the less movement of it takes place. So riding in car down highway, the street lines will zoom past fast, a little slower the trees off the highway, much slower the city in the distance. Depending on how close the clouds (compared to city), fast or slow.

If the action will take place in sky, I recommend a non moving layer of clouds in very far background, then a slow moving set behind your subject (a bird in flight?) and have clouds move past bird in front of it, according to speed of bird.

As far as jerkiness goes, have the beginning of the pic look very much like the end so there is less jump when switch back.

B+

EDIT: Sorry, I should have known you already know about different speeds, I just tried:
Trees @ .1 (half of road)
city @ .05 (half of trees)
seems smoother to me maybe bump up speed of road then half of that again for trees then half of that again for city?
« Last Edit: June 26, 2015 by B+ »
B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Parallax
« Reply #2 on: June 26, 2015 »
OK I just tried sdlBasic version of Flappy. To get THAT working I had to comment out all the sound files because they didn't work in my Windows System so THAT explains the empty slot error messages the Administrator was getting. (I think, who knows what his system is?) BTW it would be nice not to use the Full Screen setting so I can access the rest of my Windows tools should the need arise.

Cute game!!!
Once I figured out how to keep the stupid bird up in the air! Yes, the movement does seem smoother but all my attention is placed in keeping that darn bird up in the air so who is watching the background that closely?

BTW that would be another way to increase the level of play, increase the speed of things moving by, setup variables for that.

B+

Rick3137

  • Sr. Member
  • ****
  • Posts: 341
  • May the Force be with You
    • View Profile
    • Rick's Programs
Re: Parallax
« Reply #3 on: June 26, 2015 »
 Try This:

Code: [Select]
rem
rem Parallax Test
rem
import "Speed.lib"

set window 200,0,432,768
set color 188, 255, 251
cls
set redraw off

load image 1, "assets/clouds.png"
load image 2, "assets\city.png"
load image 3, "assets\trees.png"

load image 5, "assets\ground.png"

visible:
cloudsx = 0
cityx = 0
treesx = 0
groundx = 0
speed1 = 0
speed2 = 0
speed3 = 0
speed4 = 0
speed5 = 0
while 0 = 0
cls
proc moveclouds
   proc movecity
   proc movetrees
   rem movepipes
  proc moveground
redraw
  proc SPD_HoldFrame(180)

if keydown(27) = 1 then end
wend
end

procedure moveclouds()
  speed4 = speed4 + 1
  if speed4 > 20 then speed4 = 0

draw image 1, cloudsx, 462
if speed4 = 1 then cloudsx = cloudsx - 1
if cloudsx <= -432 then cloudsx = 0
endproc

procedure movecity()
  speed3 = speed3 + 1
  if speed3 > 10 then speed3 = 0

draw image 2, cityx, 507
if speed3 = 1 then cityx = cityx - 1
if cityx <= -432 then cityx = 0
endproc

procedure movetrees()
   speed2 = speed2 + 1
  if speed2 > 5 then speed2 = 0

draw image 3, treesx, 552
if speed2 = 1 then treesx = treesx - 1
if treesx <= -432 then treesx = 0
endproc

procedure moveground()
 
draw image 5, groundx, 600
groundx = groundx - 1
if groundx <= -432 then groundx = 0
endproc




B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Parallax
« Reply #4 on: June 26, 2015 »
Runs very smooth on my system.

Nice one Rick!

B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Parallax
« Reply #5 on: June 26, 2015 »
Rick you inspired me again!

Here is one with gas pedal,

press + (shift) and go faster

press - (no shift) go slower

BTW it is interesting that either / or \ seem to be OK in loading assets!

Code: [Select]
rem
rem Parallax Speed Test 2015-06-26 B+    speed version press + go faster press - go slower
rem

set window 200,0,432,720
set color 188, 255, 251
cls
set redraw off

load image 1, "assets/clouds.png"
load image 2, "assets\city.png"
load image 3, "assets\trees.png"

load image 5, "assets\ground.png"

visible:
speedlevel=1
move#=0.22
cloudsx# = 0.0
cityx# = 0.0
treesx# = 0.0
groundx# = 0.0

procedure moveclouds()
draw image 1, int(cloudsx#), 462
cloudsx = cloudsx - 0.125*move#
if cloudsx# <= -432.0 then cloudsx# = 0.0
endproc

procedure movecity()
draw image 2, int(cityx#), 507
cityx# = cityx# - 0.25*move#
if cityx# <= -432.0 then cityx# = 0.0
endproc

procedure movetrees()
draw image 3, int(treesx#), 552
treesx# = treesx# - 0.5*move#
if treesx# <= -432.0 then treesx# = 0.0
endproc

procedure moveground()
draw image 5, int(groundx#), 600
groundx# = groundx# - move#
if groundx# <= -432.0 then groundx# = 0.0
endproc

while keydown(27) = 0

k=inkey()
if chr$(k)="+" then speedlevel=speedlevel + 1
if chr$(k)="-" then speedlevel=speedlevel - 1
if speedlevel>100 then speedlevel =100
if speedlevel<1 then speedlevel =1
move#=0.2+float(speedlevel)*0.05
cls
proc moveclouds
proc movecity
proc movetrees

rem movepipes
  proc moveground

redraw
rem (see while above) if keydown(27) = 1 then end
wend


EDIT: Actually you can use - to pause game with this code instead:
Code: [Select]
if speedlevel>100 then speedlevel =100
if speedlevel<0 then speedlevel =0
move#=0.00+float(speedlevel)*0.05
« Last Edit: June 26, 2015 by B+ »
B+

johnno56

  • Guest
Re: Parallax
« Reply #6 on: June 26, 2015 »
For those of you will sound issues.

As I run with Linux, all the sound formats - wav, ogg and mp3, run without issue. Those of you that are running with Windows may be restricted to wav format. I have attached the converted files. File paths may need to be changed.

J

johnno56

  • Guest
Re: Parallax
« Reply #7 on: June 27, 2015 »
Here is the next instalment.

This version now includes a small menu screen. The 'layer' movements, submitted by forum members, have been added. Sounds updated to 'wav' format. Now has three levels. (gap between pipes will reduce slightly and the speed of the pipes will increase slightly as well)

The only parts to work on are the 'score' and 'collision detection'.

I am uncertain as to how to code collision detection with Naalaa. If anyone has a procedure on hand, could a copy please be posted?

J

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Parallax
« Reply #8 on: June 28, 2015 »
Feedback: Flaps and bing sounds fine, I assume others will be heard when collision detection code is added.

BTW isn't that when bird reaches ground level in height y or where the pipes are in relation to bird, so when bird tile x,y = pipe x,y    BANG! ?
B+

johnno56

  • Guest
Re: Parallax
« Reply #9 on: June 28, 2015 »
Yes. The other sounds will be used later. I have since added the upper and lower limits of the bird (top of screen and moving "rail" near the ground. I have looked at the collision detection in the N6 examples. Apart from trying to figure out the parameters, I think the routine will only work, if the player is moving and "bumps" into a stationary obstacle. In this game the player's "X" axis is fixed and the obstacles (pipes) are moving.

I am trying to implement the "old school" method of detecting pixels ahead of the bird. Once that is done, I can start to work on the score system.

J

johnno56

  • Guest
Re: Parallax
« Reply #10 on: June 29, 2015 »
Here is the next update.

I have finally figured out a crude collision detection.

Touching the top of screen and ground was simple. Not so with collision with the pipes. A lot of trial and error produced a collision based on the colour of the pipe border.

Having difficulty with the score. The only way I could display a score was to do so as the "moveground" was being updated. Even though "score" is incremented by 1, each time a pipe is passed, it would increment by 2 and when you get to level 3 the score increments by a 1/2. (ie: pass through two pipes to score 1)

I cannot seem to use the "flappy.ttf" to display the score. Documentation implies a 'bmp' file only. I do not know how to create a 'bmp' image file from a true type font.

J

johnno56

  • Guest
Re: Parallax
« Reply #11 on: June 29, 2015 »
Sorted out the odd scoring problem. A combination of increasing the speed of the pipes and decreasing the frame rate from 180 to 120.

Result: Score now increments by a factor of one throughout all three levels and the difficulty of the game increases with each level.

Displaying the score was a puzzler at first. Had to put the score display within the "groundmove()" procedure. (last "layer" to be displayed)

To do list:

Figure out how to load a True Type Font and use it to display a more visible score?
Create a HiScore table or a "final score" before exiting?
Maybe a "Play Again" procedure?
Maybe an animated bird?

Any other suggestions?

J

ps: Only the program is attached. Graphics/audio unchanged.

Rick3137

  • Sr. Member
  • ****
  • Posts: 341
  • May the Force be with You
    • View Profile
    • Rick's Programs
Re: Parallax
« Reply #12 on: June 30, 2015 »
 Looking good.
 Collision does not seem to work on Windows8.1 .
 I hope I can get my brain back into turbo mode so I can help with that. It took me awhile to figure out what collision involves.
 

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Parallax
« Reply #13 on: June 30, 2015 »
Confirm, pipe collisions still not detected (Windows 7-64) do we have correct version? The latest version number is still #2?
B+

johnno56

  • Guest
Re: Parallax
« Reply #14 on: June 30, 2015 »
Sorry guys. I had uploaded an 'old' version. As soon as I can get back to my PC I will upload the latest.

J