Author Topic: [BLITZMAX] Shadow of the Beast  (Read 1390 times)

0 Members and 1 Guest are viewing this topic.

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1589
  • Karma: 55
    • View Profile
[BLITZMAX] Shadow of the Beast
« on: December 17, 2009 »


need to work on tree and clouds


« Last Edit: December 20, 2009 by Hotshot »

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1589
  • Karma: 55
    • View Profile
Re: [BLITZMAX] Shadow of the Beast
« Reply #1 on: December 20, 2009 »
I cant seem get the tree right!




Code: [Select]
' Shadow of the Beast Demo :)
SuperStrict
Graphics 640,480,0

Global T_list:TList = New TList

Global Background1:TImage=LoadImage("media\bgd1_ciel.png")
Global Background2:TImage=LoadImage("media\bgd2_montagnes.PNG")
Global Background3:TImage=LoadImage("media\bgd3_sol1.png")
Global Background4:TImage=LoadImage("media\bgd4_sol2.png")
Global Background5:TImage=LoadImage("media\bgd5_sol3.png")
Global Background6:TImage=LoadImage("media\sprite_barriere.bmp")

' Put the Clouds in the sky
Global Cloud1:TImage=LoadImage("media\sprite_nuages1.bmp")
Global Cloud2:TImage=LoadImage("media\sprite_nuages2.bmp")
Global Cloud3:TImage=LoadImage("media\sprite_nuages3.bmp")
Global Cloud4:TImage=LoadImage("media\sprite_nuages4.bmp")

Global Tree  :TImage=LoadImage("media\sprite_arbre.png")


Type TBackground
     Field x: Int , y:Int
     Field x1:Int, y1:Int
     Field x2:Int, y2:Int
     Field x3:Int, y3:Int
     Field x4:Int, y4:Int
     Field x5:Int, y5:Int
Field x6:Int, y6:Int

Field c:Int,c2:Int,c3:Int,c4:Int
Field t:Int


     Method Draw()
            SetViewport 0,0,GraphicsWidth(),background1.height
            TileImage Background1,x,0

            DrawImage Cloud1,c+GraphicsWidth(),0
            DrawImage Cloud2,c2+GraphicsWidth(),10
            DrawImage Cloud3,c3+GraphicsWidth(),20
            DrawImage Cloud4,c4+GraphicsWidth(),30

            SetViewport 0,150,GraphicsWidth(),background2.height
            TileImage Background2,x2,150
            DrawImage Tree,200+t,95

  SetViewport 0,370,GraphicsWidth(),background3.height
            TileImage Background3,x3,370


  SetViewport 0,380,GraphicsWidth(),background4.height
            TileImage Background4,x4,380

  SetViewport 0,400,GraphicsWidth(),background5.height
            TileImage Background5,x5,400


  SetViewport 0,390,GraphicsWidth(),background6.height
            TileImage Background6,x6,390


            x =(x-1 )   Mod background1.width
            x2=(x2-1.5) Mod background2.width
            x3=(x3-2)   Mod background3.width
            x4=(x4-3)   Mod background4.width
            x5=(x5-5)   Mod background5.width
            x6=(x6-6)   Mod background6.width

            c=(c-3)
            c2=(c2-2)
            c3=(c3-1)
            c4=(c4-1)

            t=(t-3)
            ' Does the background come off the screen? if yes then
            ' Repeat!
            If c=<-1500
               c=800
            EndIf

            If c2=<-1500
               c2=800
            EndIf

            If c3=<-1500
               c3=800
            EndIf

            If c4=<-1500
               c4=800
            EndIf

            If t=<-2000
               t=800
            EndIf

  SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
     EndMethod

End Type

Local T:Tbackground=New Tbackground

Repeat
      Cls
      T.Draw
      Flip
Until MouseHit(1)
« Last Edit: December 20, 2009 by Hotshot »

Offline rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2325
  • Karma: 392
    • View Profile
    • http://www.rbraz.com/
Re: [BLITZMAX] Shadow of the Beast
« Reply #2 on: December 20, 2009 »
Why do you need setting viewport for each draw  image?

I believe your problem is here:
Code: [Select]
SetViewport 0,150,GraphicsWidth(),background2.height
TileImage Background2,x2,150
DrawImage Tree,200+t,95
This viewport command is clipping the tree image.

rbz ^ Codigos
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1589
  • Karma: 55
    • View Profile
Re: [BLITZMAX] Shadow of the Beast
« Reply #3 on: December 20, 2009 »
Quote
Why do you need setting viewport for each draw  image?

The reason why I did that because I didnt want tilesimage to overlap each other if that make sense.

Quote
SetViewport 0,150,GraphicsWidth(),background2.height
TileImage Background2,x2,150
DrawImage Tree,200+t,95This viewport command is clipping the tree image.

I think if I remove the viewport then it will show the whole tree...but it still cause image probelm if i remove the viewport
« Last Edit: December 20, 2009 by Hotshot »

Offline rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2325
  • Karma: 392
    • View Profile
    • http://www.rbraz.com/
Re: [BLITZMAX] Shadow of the Beast
« Reply #4 on: December 20, 2009 »
Try to reset your viewport to the default before drawing the tree:

Code: [Select]
SetViewport 0,150,GraphicsWidth(),background2.height
TileImage Background2,x2,150
SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
DrawImage Tree,200+t,95
rbz ^ Codigos
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1589
  • Karma: 55
    • View Profile
Re: [BLITZMAX] Shadow of the Beast
« Reply #5 on: December 20, 2009 »
Thank you rbz and working fine now :)

one problem....the music file i have is MOD and i am sure blitmax have FMOD library to able put music mod on.


Offline Hotshot

  • Pentium
  • *****
  • Posts: 1589
  • Karma: 55
    • View Profile
Re: [BLITZMAX] Shadow of the Beast
« Reply #6 on: December 31, 2009 »
When I run the program and I got the sound working.

when I got the demo up and running....it doesnt show the graphics on the screen but music is on

it say Unhandled exception: Attempt to access field or method of null object

I also add the code and exe files in the attachments

Code: [Select]
' Shadow of the Beast Demo :)
SuperStrict

Rem

v0.53 fixed the filelist so that only the actual song being played is highlighted regardless of changing folders
v0.52 fixed the filelist so that it only shows folders and actual modfiles
v0.51 first release

EndRem

Framework BRL.GLMax2D
Import aln.bass

SetGraphicsDriver GLMax2DDriver()

AppTitle="Alan BASS module test"

' GLOBALS
Global musicmodule:TBassmod = New TBassmod
musicmodule.Load("media\b-title.mod", 0 )
musicmodule.Play()

Graphics 640,480,0

Global T_list:TList = New TList

Global Background1:TImage=LoadImage("media\bgd1_ciel.png")
Global Background2:TImage=LoadImage("media\bgd2_montagnes.PNG")
Global Background3:TImage=LoadImage("media\bgd3_sol1.png")
Global Background4:TImage=LoadImage("media\bgd4_sol2.png")
Global Background5:TImage=LoadImage("media\bgd5_sol3.png")
Global Background6:TImage=LoadImage("media\sprite_barriere.bmp")

' Put the Clouds in the sky
Global Cloud1:TImage=LoadImage("media\sprite_nuages1.bmp")
Global Cloud2:TImage=LoadImage("media\sprite_nuages2.bmp")
Global Cloud3:TImage=LoadImage("media\sprite_nuages3.bmp")
Global Cloud4:TImage=LoadImage("media\sprite_nuages4.bmp")

Global Tree  :TImage=LoadImage("media\sprite_arbre.png")


Type TBackground
     Field x: Int , y:Int
     Field x1:Int, y1:Int
     Field x2:Int, y2:Int
     Field x3:Int, y3:Int
     Field x4:Int, y4:Int
     Field x5:Int, y5:Int
Field x6:Int, y6:Int

Field c:Int,c2:Int,c3:Int,c4:Int
Field t:Int


     Method Draw()
            SetViewport 0,0,GraphicsWidth(),background1.height  ' WHY IT IS ERROR?
            TileImage Background1,x,0

            DrawImage Cloud1,c+GraphicsWidth(),0
            DrawImage Cloud2,c2+GraphicsWidth(),10
            DrawImage Cloud3,c3+GraphicsWidth(),20
            DrawImage Cloud4,c4+GraphicsWidth(),30

            ' fixed the tree ! YAY
            SetViewport 0,150,GraphicsWidth(),background2.height
            TileImage Background2,x2,150
            SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
            DrawImage Tree,200+t,95


  SetViewport 0,370,GraphicsWidth(),background3.height
            TileImage Background3,x3,370


  SetViewport 0,380,GraphicsWidth(),background4.height
            TileImage Background4,x4,380

  SetViewport 0,400,GraphicsWidth(),background5.height
            TileImage Background5,x5,400


  SetViewport 0,390,GraphicsWidth(),background6.height
            TileImage Background6,x6,390


            x =(x-1 )   Mod background1.width
            x2=(x2-1.5) Mod background2.width
            x3=(x3-2)   Mod background3.width
            x4=(x4-3)   Mod background4.width
            x5=(x5-5)   Mod background5.width
            x6=(x6-6)   Mod background6.width

            c=(c-3)
            c2=(c2-2)
            c3=(c3-1)
            c4=(c4-1)

            t=(t-3)
            ' Does the background come off the screen? if yes then
            ' Repeat!
            If c=<-1500
               c=800
            EndIf

            If c2=<-1500
               c2=800
            EndIf

            If c3=<-1500
               c3=800
            EndIf

            If c4=<-1500
               c4=800
            EndIf

            If t=<-2000
               t=800
            EndIf

  SetViewport 0,0,GraphicsWidth(),GraphicsHeight()
     EndMethod

End Type

Local T:Tbackground=New Tbackground

Repeat
      Cls
If AppTerminate() Then
musicmodule.Free()
EndGraphics
End
End If

      T.Draw
      Flip
Until MouseHit(1)

musicmodule.Free()
EndGraphics()
End


Offline Hotshot

  • Pentium
  • *****
  • Posts: 1589
  • Karma: 55
    • View Profile
Re: [BLITZMAX] Shadow of the Beast
« Reply #7 on: January 02, 2010 »
had anyone check my demo as i got error saying Unhandled exception: Attempt to access field or method of null object

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 886
  • Karma: 63
    • View Profile
    • zac-interactive
Re: [BLITZMAX] Shadow of the Beast
« Reply #8 on: January 02, 2010 »
Quote
Unhandled exception: Attempt to access field or method of null object

The error you are getting is because the variables are out of scope, and the content has been set to null. Blitzmax comes with built in garbage collection, so it keeps an eye out for variables, types, etc. and if they no longer are refered to, or becomes out of scope, then it clears them out to free up memory.

I am not really sure why you want to use a type for the drawing. It seems like you are overly complicating things. Why not just store the images and x values in an array, or simply variables and then have a regular while/wend loop where you draw them.

Another thing I spotted was that you have a line where you are adding a floating point value to an integer, which makes no sense since .5 will be rounded up to 1.0 anyways.

When running in debug mode, and the code stops, then you can use the right side of the IDE, where it lists various variable states and such. If you take a look there you will find that your images has been cleared to null, which is why they will not show and why the code halts with an error.

I would recomend that you take another approach instead of the whole type thing. Types are really great, but not always the route to go. Sometimes a more simple approach is much better, especially since its not a big complicated project you are working on.

[edit]

Shortly after writing the above, I decided to take a look at your code anyways. And the reason why your images are not shown and the code breaks down is that they are not loaded at all. I am not sure you fully understands the Framework/Import part of the language. What it does is it allows you to pick only the parts of the blitzmax language you want to include into your file. The Framework command lets you pick the main starting library that your project will be build on. The Import command lets you pick any other library that you would want.

In your code, you have only the two lines that was in the test code I made for you. But since my example only had to open a graphics window and load and play a module, I only had those two lines, because that was all I needed to include.

But in this project you have here, you are attempting to load two different kinds of image files. What code should be handling that then? Nothing you have added, so instead it just breaks down. You will have to make sure that you include all code needed, if you want to make use of the Framework/Import command feature.

There is a tool that can help you picking what to use as framework and imports, if you are uncertain. You can get it from this website:

http://homepage.ntlworld.com/config/fa/

If you add the following imports to your code, then your code should compile and work:

Code: [Select]
Import BRL.PNGLoader
Import BRL.BMPLoader
« Last Edit: January 02, 2010 by zawran »

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1589
  • Karma: 55
    • View Profile
Re: [BLITZMAX] Shadow of the Beast
« Reply #9 on: January 03, 2010 »
hiya zawran,

thank you for explaining me about Unhandled exception: Attempt to access field or method of null object and it was good explain on what you have said.

Quote
Import BRL.PNGLoader
Import BRL.BMPLoader

That interesting to know :)
thank you very much.

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1589
  • Karma: 55
    • View Profile
Re: [BLITZMAX] Shadow of the Beast
« Reply #10 on: September 06, 2011 »
Just need uploading to my Website and yep, it`s working lol :)