Author Topic: [BlitzMax] Hellfire  (Read 3880 times)

0 Members and 1 Guest are viewing this topic.

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
[BlitzMax] Hellfire
« on: August 13, 2009 »
I have convert from Blitz 3D to BlitzMax but some of part code isnt working for reason.....could you tell me why please? ???

Code: [Select]
' specail thanks to therevills for Tsprite and Tplayer
SuperStrict
Graphics 800,600,0

Cls
'create player image
SetColor 255,255,255
DrawRect 0,0,50,30

Global playerImg:TImage=CreateImage(50,30,1,DYNAMICIMAGE|MASKEDIMAGE)
GrabImage playerImg,0,0

MidHandleImage playerImg

Type TSprite
Field x#,y#
Field dx#,dy#
Field yspeed#

Field image:TImage
Field w%,h%
Field w2%,h2%

Method draw()
DrawImage image, x, y
End Method

End Type

Global FirstX:Int =0
Global LastX :Int=100
Global Firsty:Int=0
Global lastX :Int=100

Type TPlayer Extends TSprite

Function Create:TPlayer(x#,y#)
Local p:TPlayer = New TPlayer
p.x = x
p.y = y
p.yspeed = 3
p.image = playerImg
p.w = ImageWidth(playerImg)
p.h = ImageHeight(playerImg)
p.w2 = p.w/2
p.h2 = p.h/2
Return p
End Function

Method update()
If KeyDown(KEY_UP)
y =y-yspeed
EndIf

If KeyDown(KEY_DOWN)
y =y+yspeed
EndIf

If y<=15   Then y=15
   If y>=585  Then y=585

End Method
End Type

Type Rock
    Field x#,y#
    Field destroyed%

Function Make_Rock(r.x,r.y)
For i = 0 To 150
                r.rock = New Rock ' Create rocks
                r.x = Rand(FirstX,LastX)    ' The starting X
                r.y = Rand(FirstY,LastY)    ' The starting Y
                r.destroyed = False
             Next
End Function

Method Update()
      ' Set color For the rocks
           SetColor 255,80,10

           ' --------------Draw rocks----------------
           For r.rock = Each Rock
               DrawRect r.x,r.y,20,20
               r.x = r.x - 10
               If r.x < 0 Then ' If the rocks reaches the Left
                  r.x = Rand(580,950) ' of the screen, draw
                  r.y = Rand(1,580) ' it at the Left
               EndIf

               If RectsOverlap(p.x,p.y,30,15,r.x,r.y,20,20) Then
                  lifes = lifes - 1
                  If lifes =< 0 Then
                     p.x = -100
                     p.y = -100
                  EndIf
               EndIf

             If RectsOverlap(bullet_x,bullet_y,5,2,r.x,r.y,20,20) Then
                Score=Score+1
               ' Delete r.rock
                bullet_enabled = False
                bullet_x = x + 5
                bullet_y = y + 10
             EndIf
         Next

      ' if the rock go off the screen then kill it :)
      If r.x<=0 Then r.destroyed = False
End Method

End Type

SetColor 255,255,255
SetBlend SOLIDBLEND

Global player:TPlayer = TPlayer.Create(30,200)

Make_Rock(r.x,r.y)

While Not AppTerminate()=1 And Not KeyHit(KEY_ESCAPE)
Cls
player.update()
player.draw()

rock.update()
rock.draw()
Flip
Wend

edited by rbz: added code tag
« Last Edit: August 14, 2009 by rbz »

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [BlitzMax] Hellfire
« Reply #1 on: August 13, 2009 »
I dont have BMAX on me at present, I think you need to do the same as you've done for the player global, and add it to a TList.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [BlitzMax] Hellfire
« Reply #2 on: August 17, 2009 »
Well, you really should consider making a global list for each type. Each type should have a function that returns a new instance of that type and adds it to a global list. Also, you might consider making an update method in the type which will move and draw the type.  You want your objects stored in some container or they will get deleted as soon as all references to them go out of scope. Bmax has automatic garbage collection. If you use "new" you must store a reference to that new object either in a list or other structure. Or it will be deleted automatically.

You then can do something like this.

Code: [Select]
global ship_list:tlist = new tlist

type ship
field x:float, y:float

function construct(x_pos:float, y_pos:float)
    local s:ship = new ship
    s.x=x_pos
    s.y =y_pos
    listaddlast(ship_list,s)
endfunction

method draw()
'draw sprite here
endmethod

method move()
'move ship here
endmethod

method update()
move()
draw()
endmethod

method destroy()
    listremove(ship_list,self)
endmethod

endtype



Code: [Select]
For local s:ship = eachin(ship_list)
     s.update()
next
« Last Edit: August 17, 2009 by Pixel_Outlaw »
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: [BlitzMax] Hellfire
« Reply #3 on: August 17, 2009 »
You might also get a lot from a visit to this page, which list a lot of blitzmax tutorials:

http://www.2dgamecreators.com/blitzmax/resources/

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: [BlitzMax] Hellfire
« Reply #4 on: August 17, 2009 »
Pixel_Outlaw :  that code example was interesting and worth learning from it.

Quote
You might also get a lot from a visit to this page, which list a lot of blitzmax tutorials:

http://www.2dgamecreators.com/blitzmax/resources/

zawran :  thanks for link   ;D