Small and simple demo example

Discuss any general programming issues here
Post Reply
jalih
Posts: 281
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Small and simple demo example

Post 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...
User avatar
Tuxedo
Posts: 355
Joined: Sun Feb 14, 2010 12:41 pm

Re: Small and simple demo example

Post by Tuxedo »

really nice!
Unfortunately the current Hollywood scroll problem(it was scattering) was here too...
Simone"Tuxedo"Monsignori, Perugia, ITALY.
ArtBlink
Posts: 484
Joined: Mon Nov 01, 2010 10:37 am
Location: Albert - France
Contact:

Re: Small and simple demo example

Post 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
User avatar
Tuxedo
Posts: 355
Joined: Sun Feb 14, 2010 12:41 pm

Re: Small and simple demo example

Post by Tuxedo »

mmm...
here no changes with that...
Always scattering...
Simone"Tuxedo"Monsignori, Perugia, ITALY.
jalih
Posts: 281
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: Small and simple demo example

Post 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()
jalih
Posts: 281
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: Small and simple demo example

Post 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()
User avatar
Tuxedo
Posts: 355
Joined: Sun Feb 14, 2010 12:41 pm

Re: Small and simple demo example

Post 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...
Simone"Tuxedo"Monsignori, Perugia, ITALY.
jalih
Posts: 281
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: Small and simple demo example

Post 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.
Post Reply