Page 1 of 1

Small and simple demo example

Posted: Mon Sep 19, 2011 11:15 pm
by jalih
Another small and simple but still quite fun demo example

I just made some fixes and additions to my libraries. While testing, I ported this from Inferno using my primitives module.

Any feedback is welcome...

Re: Small and simple demo example

Posted: Fri Sep 30, 2011 11:34 pm
by Tuxedo
really nice!
Unfortunately the current Hollywood scroll problem(it was scattering) was here too...

Re: Small and simple demo example

Posted: Mon Oct 03, 2011 8:14 pm
by ArtBlink
@Tuxedo:

Change your line in the code:


scroll = SetInterval(Nil, p_Scroll, 20)

by

SetInterval(Nil, p_Scroll, 10)

It's much nice on my PC

Re: Small and simple demo example

Posted: Mon Oct 03, 2011 10:29 pm
by Tuxedo
mmm...
here no changes with that...
Always scattering...

Re: Small and simple demo example

Posted: Tue Oct 04, 2011 12:34 pm
by jalih
Try this one (You need my Hollywood Game Framework library):

Code: Select all


@DISPLAY {Width = 640, Height = 480, Title = "Hollywood Game Framework Scroll Test"}


; Include game framework
@INCLUDE "hgf/game.hws"


; Include game states


; Include modules


; Data files
@BRUSH 1, "bg.jpg" ; Some really large picture



; Setup
Function game.load()
   bg = image:new(1)
   xy = point:new()
   speed = 100
   game:setUpdateRate(60)
EndFunction


; Draw
Function game.draw()
   game.buffer:drawImg(bg.r, bg, xy)
EndFunction


; Update
Function game.update(dt)
   If IsKeyDown("LEFT") Then xy.x = xy.x - speed * dt
   If xy.x < 0 Then xy.x = 0

   If IsKeyDown("RIGHT") Then xy.x = xy.x + speed * dt
   If xy.x > bg.r:dx() - game.buffer.r:dx() Then xy.x = bg.r:dx() - game.buffer.r:dx()

   If IsKeyDown("UP") Then xy.y = xy.y - speed * dt
   If xy.y < 0 Then xy.y = 0

   If IsKeyDown("DOWN") Then xy.y = xy.y + speed * dt
   If xy.y > bg.r:dy() - game.buffer.r:dy() Then xy.y = bg.r:dy() - game.buffer.r:dy()
   
   If IsKeyDown("ESC") Then End

EndFunction



; Go!
game:go()

Re: Small and simple demo example

Posted: Tue Oct 04, 2011 3:11 pm
by jalih
Sorry, I made a small typo: drawing rectancle's size should naturally be the same as the rectangle of the drawing buffer:

Code: Select all


@DISPLAY {Width = 640, Height = 480, Title = "Hollywood Game Framework Scroll Test"}


; Include game framework
@INCLUDE "hgf/game.hws"


; Include game states


; Include modules


; Data files
@BRUSH 1, "bg.jpg" ; Some really large picture



; Setup
Function game.load()
   bg = image:new(1)
   xy = point:new()
   speed = 100
   game:setUpdateRate(60)
EndFunction


; Draw
Function game.draw()
   game.buffer:drawImg(game.buffer.r, bg, xy) ; parameters: drawing rectancle, image to draw, offset point in image) 
EndFunction


; Update
Function game.update(dt)
   If IsKeyDown("LEFT") Then xy.x = xy.x - speed * dt
   If xy.x < 0 Then xy.x = 0

   If IsKeyDown("RIGHT") Then xy.x = xy.x + speed * dt
   If xy.x > bg.r:dx() - game.buffer.r:dx() Then xy.x = bg.r:dx() - game.buffer.r:dx()

   If IsKeyDown("UP") Then xy.y = xy.y - speed * dt
   If xy.y < 0 Then xy.y = 0

   If IsKeyDown("DOWN") Then xy.y = xy.y + speed * dt
   If xy.y > bg.r:dy() - game.buffer.r:dy() Then xy.y = bg.r:dy() - game.buffer.r:dy()
   
   If IsKeyDown("ESC") Then End

EndFunction



; Go!
game:go()

Re: Small and simple demo example

Posted: Wed Oct 05, 2011 12:15 am
by Tuxedo
onestly dont seems to me so smooth...
And also the weird thing was that I cant get 100% cpu usage with my old example with double bufferig way posted somewhere here...
So a problem have to happen somewhere in the hollywood core...

Re: Small and simple demo example

Posted: Wed Oct 05, 2011 10:16 am
by jalih
Tuxedo wrote:onestly dont seems to me so smooth...
And also the weird thing was that I cant get 100% cpu usage with my old example with double bufferig way posted somewhere here...
So a problem have to happen somewhere in the hollywood core...
On my Windows machine, it's not too bad with small screen size (some minor flicks are still noticeable, though).

My scrolling example uses double buffer for drawing too and if I check ( game:getFPS() function ), framerate should not drop below 60 (it's set to 60 in the example).


If you want 100% cpu load on your scrolling code, then remove all timing from scrolling loop except VWait() call before the screen update.