PDA

Click to See Complete Forum and Search --> : Little prob with my game (help needed)


TheKGBspy
Jan 8th, 2002, 08:23 AM
ok i have a little prob. i want to know how to use bitblt for my game.

my game is a rts, a commandos style game, that u must infiltrate ennemy base with elite soldier. i want to use bitblt to load my picture for the color mask (i dont kknow how to use it and incorpor it into my game), work in frame per second, because now im using a timer (yep one timer for 6 soldier ;) ), and finnaly i want to know how to delete a frame in the memory because my soldier have 6 frame per animation ( ex the firering animation while the soldier stand up have 6 frame per derection (8 direction)
so in all it have 6 * 8 frame for firering) and putting all that in one bmp will be long but its is better?

i have also my map editor for my game and i want to know how to unload picture from the memory when i dont looking a tile.


there is my map editor coding:



Private Sub BoNextTile_Click()
If TileView = NbOfTile Then TileView = 0
TileView = TileView + 1
TileSelectionSub
End Sub

Private Sub BoPrevTile_Click()
If TileView = 1 Then TileView = (NbOfTile + 1)
TileView = TileView - 1
TileSelectionSub
End Sub

Private Sub TileSelectionSub()
SelectionTile.Picture = LoadPicture(App.Path & "/tiles/" & TypeOfTerrain & "/" & TileView & ".bmp")
LaTileInfo.Caption = "Type :" & TypeOfTerrain & " Tile #: " & TileView
SelectionTile.Left = (PicSelectTile.Width - SelectionTile.Width) / 2
SelectionTile.Top = (PicSelectTile.Height - SelectionTile.Height) / 2
SelectiontileCase.Width = SelectionTile.Width
SelectiontileCase.Height = SelectionTile.Height
SelectiontileCase.Top = SelectionTile.Top
SelectiontileCase.Left = SelectionTile.Left

End Sub

Private Sub Form_Activate()

If LoadingNew = True Then
Largeur = Int(Map.Width / ImMapTile(0).Width)
Hauteur = Int(Map.Height / ImMapTile(0).Height)
RadarTile(0).Width = Int((ImMapTile(0).Width / Map.Width) * Radar.Width)
RadarTile(0).Height = Int((ImMapTile(0).Height / Map.Height) * Radar.Height)

LoadingTest = Largeur * Hauteur

NbTile = 0
For l = 0 To Largeur
For h = 0 To Hauteur
Randomize
GrassTile = Int((16 * Rnd) + 1)
NbTile = NbTile + 1
Load ImMapTile(NbTile)
Load RadarTile(NbTile)
RadarTile(NbTile).Visible = True
RadarTile(NbTile).Left = RadarTile(0).Width * l
RadarTile(NbTile).Top = RadarTile(0).Height * h
RadarTile(NbTile).BackColor = &H8000&
RadarTile(NbTile).BorderColor = RadarTile(NbTile).BackColor
'ImMapTile(NbTile).Picture = LoadPicture(App.Path & "/tiles/grass/" & GrassTile & ".bmp")
ImMapTile(NbTile).Visible = True
ImMapTile(NbTile).Left = ImMapTile(0).Width * l
ImMapTile(NbTile).Top = ImMapTile(0).Height * h
ImMapTile(NbTile).ZOrder 1
If loadingbar.Value > 99 Then GoTo Suite
loadingbar.Value = (NbTile / LoadingTest) * 100
Suite:
Debug.Print NbTile
Next h
Next l
Radar.Visible = True
Map.Visible = True
TypeOfTerrain = "Grass"
TileView = 1
NbOfTile = 16
SelectionTile.Picture = LoadPicture(App.Path & "/tiles/" & TypeOfTerrain & "/" & TileView & ".bmp")

RectRadar.Height = (MapView.Height * Radar.Height) / Map.Height
RectRadar.Width = (MapView.Width * Radar.Width) / Map.Width

LoadingNew = False

loadingbar.Value = 0
End If

End Sub

Private Sub Form_Load()
CellLoad = 0
LoadingNew = False
ImMapTile(0).Picture = LoadPicture(App.Path & "/tiles/" & "grass" & "/" & "1.bmp")
SelectTile.Width = ImMapTile(0).Width
SelectTile.Height = ImMapTile(0).Height
RectRadar.Top = 0
RectRadar.Left = 0


For f = 0 To 3

Select Case f
Case 0
Frame(0).Top = 1920
Case 1
Frame(1).Top = 2170
Case 2
Frame(2).Top = 2425
Case 3
Frame(3).Top = 2680
End Select
Frame(f).Height = 255

Next f

End Sub

Private Sub Form_Unload(Cancel As Integer)
For u = 1 To NbTile
Unload ImMapTile(u)
Next u
End Sub

Private Sub Frame_Click(Index As Integer)


If Frame(Index).Height = 1815 Then
Frame(Index).Height = 255

For f = 0 To 3
Frame(f).Visible = True
Next f

Select Case Index
Case 0
Frame(0).Top = 1920
Case 1
Frame(1).Top = 2170
Case 2
Frame(2).Top = 2425
Case 3
Frame(3).Top = 2680
End Select
PicMenu(Index).Visible = False
Exit Sub

End If

If Frame(Index).Height = 255 And Frame(Index).Width = 2295 Then
Frame(Index).Height = 1815
Frame(Index).Top = 1920
PicMenu(Index).Visible = True


Select Case Index
Case 0
MenuSelect = "Terrain"
Case 1
MenuSelect = "Units"
Case 2
MenuSelect = "Buildings"
Case 3
MenuSelect = "Cell"
End Select

For f = 0 To 3
Frame(f).Visible = False
Next f
Frame(Index).Visible = True
End If
Debug.Print MenuSelect

End Sub


Private Sub Frame_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Index
Case 0
Frame(1).ForeColor = &H80000012
Frame(2).ForeColor = &H80000012
Frame(3).ForeColor = &H80000012
Frame(0).ForeColor = &H404040

Case 1
Frame(0).ForeColor = &H80000012
Frame(2).ForeColor = &H80000012
Frame(3).ForeColor = &H80000012
Frame(1).ForeColor = &H404040

Case 2
Frame(1).ForeColor = &H80000012
Frame(0).ForeColor = &H80000012
Frame(3).ForeColor = &H80000012
Frame(2).ForeColor = &H404040

Case 3
Frame(1).ForeColor = &H80000012
Frame(2).ForeColor = &H80000012
Frame(0).ForeColor = &H80000012
Frame(3).ForeColor = &H404040


End Select


End Sub

Private Sub ImMapTile_Click(Index As Integer)
If MenuSelect = "Terrain" Then
ImMapTile(Index).Picture = ImSelectedTile.Picture
If LaSelectedTileType.Caption = "Grass" Then
RadarTile(Index).BackColor = &H8000&
RadarTile(Index).BorderColor = &H8000&
ElseIf LaSelectedTileType.Caption = "Water" Then
RadarTile(Index).BackColor = &HC0C000
RadarTile(Index).BorderColor = &HC0C000
End If
End If

If MenuSelect = "Cell" Then
If CellWay(1).Value = True Then
CellLoad = CellLoad + 1
Load ImMapCelltag(CellLoad)
ImMapCelltag(CellLoad).Visible = True
ImMapCelltag(CellLoad).Top = ImMapTile(Index).Top
ImMapCelltag(CellLoad).Left = ImMapTile(Index).Left
ImMapCelltag(CellLoad).ZOrder 0
ImMapCelltag(CellLoad).Enabled = False
End If
If CellWay(0).Value = True Then
WayLoad = WayLoad + 1
Load ImMapWaypoint(WayLoad)
ImMapWaypoint(WayLoad).Visible = True
ImMapWaypoint(WayLoad).Top = ImMapTile(Index).Top
ImMapWaypoint(WayLoad).Left = ImMapTile(Index).Left
ImMapWaypoint(WayLoad).ZOrder 0
ImMapWaypoint(WayLoad).Enabled = False
End If
End If


End Sub

Private Sub ImMapTile_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
SelectTile.Top = ImMapTile(Index).Top
SelectTile.Left = ImMapTile(Index).Left
End Sub

Private Sub MeFiExit_Click()
End
End Sub

Private Sub MeFiNew_Click()
Load FoNew
FoNew.Visible = True
End Sub

Private Sub Option1_Click(Index As Integer)
Debug.Print Index
Select Case Index
Case 0
TypeOfTerrain = "Grass"
NbOfTile = 16
Case 1
Case 2
TypeOfTerrain = "Rock"
NbOfTile = 1
Case 3
Case 4
Case 5
TypeOfTerrain = "Water"
NbOfTile = 1
End Select
TileView = 1
LaTileInfo.Caption = "Type :" & TypeOfTerrain & " Tile #: " & TileView
SelectionTile.Picture = LoadPicture(App.Path & "/tiles/" & TypeOfTerrain & "/" & TileView & ".bmp")
SelectionTile.Left = (PicSelectTile.Width - SelectionTile.Width) / 2
SelectionTile.Top = (PicSelectTile.Height - SelectionTile.Height) / 2
SelectiontileCase.Width = SelectionTile.Width
SelectiontileCase.Height = SelectionTile.Height
SelectiontileCase.Top = SelectionTile.Top
SelectiontileCase.Left = SelectionTile.Left
End Sub

Private Sub Radar_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next

Select Case Button

Case 1
RectRadar.Top = Y - (RectRadar.Height / 2)
RectRadar.Left = X - (RectRadar.Width / 2)

If (RectRadar.Left + RectRadar.Width) > Radar.Width Then
RectRadar.Left = Radar.Width - RectRadar.Width
End If

If RectRadar.Left < 0 Then
RectRadar.Left = 0
End If

If (RectRadar.Top + RectRadar.Height) > Radar.Height Then
RectRadar.Top = Radar.Height - RectRadar.Height
End If

If RectRadar.Top < 0 Then
RectRadar.Top = 0
End If

Map.Left = -((RectRadar.Left * Map.Width) / Radar.Width)
Map.Top = -((RectRadar.Top * Map.Height) / Radar.Height)

End Select

Map.SetFocus

End Sub

Private Sub SelectionTile_Click()
LaSelectedTileType.Caption = TypeOfTerrain
LaSelectedTileNb.Caption = TileView
ImSelectedTile.Picture = SelectionTile.Picture
'LaTileSelect.Caption = "Type :" & TypeOfTerrain & " Tile #: " & TileView
End Sub


i have a module that contain all my variable


Public Largeur As Long
Public Hauteur As Long
Public NbTile As Long
Public GrassTile As Integer
Public TypeOfTerrain As String
Public TileView As Integer
Public IsMouse1Down As Boolean
Public NbOfTile As Integer
Public MiniMapTileH As Long
Public MiniMapTileL As Long
Public TileIndex As Long
Public LoadingNew As Boolean
Public LoadingTest As Long
Public AlreadyMapped As Boolean
Public MenuSelect As String
Public Choix As Long
Public CellLoad As Long
Public WayLoad As Long

TheKGBspy
Jan 8th, 2002, 08:39 AM
Private Sub BoCancel_Click()
Unload Me
End Sub

Private Sub BoOK_Click()
If AlreadyMapped = True Then
FoMain.Radar.Visible = False
FoMain.Map.Visible = False
For u = 1 To NbTile
Unload FoMain.RadarTile(u)
Unload FoMain.ImMapTile(u)
Next u
DoEvents
End If

If TxtHeight.Text = "" Or TxtWidth.Text = "" Then
MsgBox ("Il manque des informations a quelque part")
Exit Sub
Else
FoMain.Map.Height = FoMain.ImMapTile(0).Height * TxtHeight.Text
FoMain.Map.Width = FoMain.ImMapTile(0).Width * TxtWidth.Text
LoadingNew = True
AlreadyMapped = True
Unload Me
FoMain.SetFocus
End If
End Sub

CornedBee
Jan 8th, 2002, 09:06 AM
arrrgh, timers

Mman
Jan 8th, 2002, 07:33 PM
Or you can always look at my bitblt tutorial :D www.geocities.com/mman76dev

TheKGBspy
Jan 10th, 2002, 08:37 AM
ok ill explain more how my game work. i have 6 soldier now, they are walking, crawling, firering...

and there is what the timer have to make them move or firering....


Private Sub Timer1_Timer()
On Error Resume Next

Timer1.Interval = speed


For k = 0 To 5

If Image1(k).Tag = "On" Then

If IsFirering(k + 1) <> True Then

ConscAnim(k + 1) = ConscAnim(k + 1) + 1
If ConscAnim(k + 1) = 7 Then
ConscAnim(k + 1) = 1
End If

Image1(k).Picture = LoadPicture(App.Path + "\" & MarcheRamp(k + 1) & Angle(k + 1) & ConscAnim(k + 1) & ".gif")
Image1(k).Left = Image1(k).Left + Hori(k + 1)
Image1(k).Top = Image1(k).Top + Verti(k + 1)

If Angle(k + 1) = "n" And (Image1(k).Top < ConscY(k + 1) - 600) Then
Image1(k).Picture = LoadPicture(App.Path + "\" & MarcheRamp(k + 1) & Angle(k + 1) & ".gif")
ConscAnim1 = 0
Image1(k).Tag = "Off"
End If

If Angle(k + 1) = "e" And (Image1(k).Left > ConscX(k + 1) - (Image1(k).Width / 2)) Then
Image1(k).Picture = LoadPicture(App.Path + "\" & MarcheRamp(k + 1) & Angle(k + 1) & ".gif")
ConscAnim1 = 0
Image1(k).Tag = "Off"
End If

If Angle(k + 1) = "w" And (Image1(k).Left < ConscX(k + 1) - (Image1(k).Width / 2)) Then
Image1(k).Picture = LoadPicture(App.Path + "\" & MarcheRamp(k + 1) & Angle(k + 1) & ".gif")
ConscAnim1 = 0
Image1(k).Tag = "Off"
End If

If Angle(k + 1) = "s" And (Image1(k).Top > ConscY(k + 1) - 600) Then
Image1(k).Picture = LoadPicture(App.Path + "\" & MarcheRamp(k + 1) & Angle(k + 1) & ".gif")
ConscAnim1 = 0
Image1(k).Tag = "Off"
End If

If Angle(k + 1) = "ne" And Image1(k).Left > (ConscX(k + 1) - (Image1(k).Width / 2)) Then
Angle(k + 1) = "n"
Hori(k + 1) = "0"
Verti(k + 1) = "-60"
End If

If Angle(k + 1) = "ne" And Image1(k).Top < (ConscY(k + 1) - 600) Then
Angle(k + 1) = "e"
Hori(k + 1) = "60"
Verti(k + 1) = "0"
End If

If Angle(k + 1) = "nw" And Image1(k).Left < (ConscX(k + 1) - (Image1(k).Width / 2)) Then
Angle(k + 1) = "n"
Hori(k + 1) = "0"
Verti(k + 1) = "-60"
End If

If Angle(k + 1) = "nw" And Image1(k).Top < (ConscY(k + 1) - 600) Then
Angle(k + 1) = "w"
Hori(k + 1) = "-60"
Verti(k + 1) = "0"
End If

If Angle(k + 1) = "se" And Image1(k).Left > (ConscX(k + 1) - (Image1(k).Width / 2)) Then
Angle(k + 1) = "s"
Hori(k + 1) = "0"
Verti(k + 1) = "60"
End If

If Angle(k + 1) = "se" And Image1(k).Top > (ConscY(k + 1) - 600) Then
Angle(k + 1) = "e"
Hori(k + 1) = "60"
Verti(k + 1) = "0"
End If

If Angle(k + 1) = "sw" And Image1(k).Left < (ConscX(k + 1) - (Image1(k).Width / 2)) Then
Angle(k + 1) = "s"
Hori(k + 1) = "0"
Verti(k + 1) = "60"
End If

If Angle(k + 1) = "sw" And Image1(k).Top > (ConscY(k + 1) - 600) Then
Angle(k + 1) = "w"
Hori(k + 1) = "-60"
Verti(k + 1) = "0"
End If

Shape1(k).Top = (Image1(k).Top * Picture3.Height) / Picture2.Height
Shape1(k).Left = (Image1(k).Left * Picture3.Width) / Picture2.Width

ElseIf IsFirering(k + 1) = True Then

ConscAnim(k + 1) = ConscAnim(k + 1) + 1
Image1(k).Picture = LoadPicture(App.Path + "\fire" & MarcheRamp(k + 1) & Angle(k + 1) & ConscAnim(k + 1) & ".gif")


Select Case ConscAnim(k + 1)

Case 1
Randomize
son = Int((4 * Rnd) + 1)
FoHidMusic.MediaPlayer1.Open (App.Path + "\fire-" & son & ".wav")

Case 7
Image1(k).Picture = LoadPicture(App.Path + "\" & MarcheRamp(k + 1) & Angle(k + 1) & ".gif")

Case 15
ConscAnim(k + 1) = 0
End Select

End If

End If ' fin conscript 1


Next k


'LaImX.Caption = "Im. X:" & Image1(PicIndex).Left + (Image1(PicIndex).Width / 2)
'LaImY.Caption = "Im. Y:" & Image1(PicIndex).Top + 600

'Energiebar



End Sub


just tell me if there is a better way, and how to put the dc thing in my timer becauase its a little laggy when the 6 soldiers run all togheter!!

and this my sub for detecting the angle and direction on the soldier must take:


Public Sub DetectAngle()


For I = 0 To 5

If Image4(I).Tag = "Off" Then
GoTo Prochain
Else
If x2 < Image1(I).Left And y2 < (Image1(I).Top + Image1(I).Height) And y2 > Image1(I).Top Then
Angle(I + 1) = "w"
Hori(I + 1) = "-60"
Verti(I + 1) = "0"
End If

If x2 > Image1(I).Left And y2 < (Image1(I).Top + Image1(I).Height) And y2 > Image1(I).Top Then
Angle(I + 1) = "e"
Hori(I + 1) = "60"
Verti(I + 1) = "0"
End If

If y2 < Image1(I).Top And x2 > Image1(I).Left And x2 < (Image1(I).Left + Image1(I).Width) Then
Angle(I + 1) = "n"
Verti(I + 1) = "-60"
Hori(I + 1) = "0"
End If

If y2 > Image1(I).Top And x2 > Image1(I).Left And x2 < (Image1(I).Left + Image1(I).Width) Then
Angle(I + 1) = "s"
Verti(I + 1) = "60"
Hori(I + 1) = "0"
End If

If y2 < Image1(I).Top And x2 > (Image1(I).Left + Image1(I).Width) Then
Angle(I + 1) = "ne"
Verti(I + 1) = "-30"
Hori(I + 1) = "30"
End If

If y2 > (Image1(I).Top + Image1(I).Height) And x2 > (Image1(I).Left + Image1(I).Width) Then
Angle(I + 1) = "se"
Verti(I + 1) = "30"
Hori(I + 1) = "30"
End If

If x2 < Image1(I).Left And y2 < Image1(I).Top Then
Angle(I + 1) = "nw"
Hori(I + 1) = "-30"
Verti(I + 1) = "-30"
End If

If x2 < Image1(I).Left And y2 > (Image1(I).Top + Image1(I).Height) Then
Angle(I + 1) = "sw"
Hori(I + 1) = "-30"
Verti(I + 1) = "30"
End If

ConscX(I + 1) = x2
ConscY(I + 1) = y2


Image1(I).Tag = "On"

Debug.Print Angle(I + 1), Hori(I + 1), Verti(I + 1), Image1(I).Tag, Image4(I).Tag


End If

Prochain:

Next I



End Sub


how my game work: you select the soldier, click on the map and the soldier move where you have order to it.

it is the best way to do not put timer and put a fps system? and for my lagging prob, how can i put my image in memory? Using dc thing?

CornedBee
Jan 10th, 2002, 08:59 AM
please, use [/Highlight] and [Highlight=VB] when writing code.

TheKGBspy
Jan 10th, 2002, 09:16 AM
all done!! i edit all my post. and tanx a i was wondering wath was the command for make vb code appear in vb code color.. so can you help me now?

TheKGBspy
Jan 10th, 2002, 09:40 AM
littile pic of my game. for the graphic they are not final!!! i took them only for code my game first and after ill make my own graphic, so if i took graphic of game, its only for alpha testing purpose!

CornedBee
Jan 10th, 2002, 12:37 PM
Without looking at your code I'd say:
If you're only drawing the tiles you see it is no problem. Just add a boolean variable to each tile. Set all to false before you draw. When you draw a tile, you also set it's variable to true. After you've draw, you look which tiles still have false and unload them if ot already happened. This also means that they need to be reloaded if they need to be drawn again, so you must catch that possibility. I don't have code, I can't do VB.