|
Mostrar Mensajes
|
Páginas: 1 2 3 4 [5] 6
|
43
|
Programación / Programación Visual Basic / Re: Cambiar objeto a variable
|
en: 14 Octubre 2007, 04:37 am
|
Solucionado... XDDDD el error era mas tonto de lo que creía... Modificado: He solucionado, era un error mio, xDDDDD
Ahora me salta error en tiempo de ejecución:
"el subindice está fuera del intervalo"
Eso me salta, al comprobar que esta colisionando... :S
Código completo:
Código: Public m_System As New dx_System_Class Dim Bloque(1 To 10) As GFX_Rect Dim c As GFX_Rect Dim i As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case vbKeyLeft Char.Left = Char.Left - 160 c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height
'!!!!!!!!!!!!!!!AQUI TENIA QUE PONER EL RANGO DE NUMEROS
LabelColision.Caption = m_System.MATH_IntersectRect(Bloque(i), c) 'Si hay colision, el char "no se mueve" If LabelColision.Caption = "Verdadero" Then Char.Left = Char.Left + 160 Label1.Caption = "Colision" End If
'!!!!!!!!!!!!!!!!!AQUI EL FINAL (Next i)
Case vbKeyRight Char.Left = Char.Left + 160 c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height LabelColision.Caption = m_System.MATH_IntersectRect(Bloque(i), c)
If LabelColision.Caption = "Verdadero" Then Char.Left = Char.Left - 160 Label1.Caption = "Colision" End If Case vbKeyDown Char.Top = Char.Top + 160 c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height LabelColision.Caption = m_System.MATH_IntersectRect(Bloque(i), c) If LabelColision.Caption = "Verdadero" Then Char.Top = Char.Top - 160 Label1.Caption = "Colision" End If Case vbKeyUp Char.Top = Char.Top - 160 c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height
LabelColision.Caption = m_System.MATH_IntersectRect(Bloque(i), c) If LabelColision.Caption = "Verdadero" Then Char.Top = Char.Top - 160 Label1.Caption = "Colision" End If
PD: He dejado el codigo anterior, por si sirve de algo, para que se entienda todo. Muxisisimas gracias a todos, aunque en especial a ranslsad, que a sido el que me ha hecho dar vueltas a la cabeza.. xDDD Gracias :p Tema zanjado.
|
|
|
44
|
Programación / Programación Visual Basic / Re: Cambiar objeto a variable
|
en: 14 Octubre 2007, 03:51 am
|
Modificado: He solucionado, era un error mio, xDDDDD Ahora me salta error en tiempo de ejecución: "el subindice está fuera del intervalo" Eso me salta, al comprobar que esta colisionando... :S Código completo: Public m_System As New dx_System_Class Dim Bloque(1 To 10) As GFX_Rect Dim c As GFX_Rect Dim i As Integer
Private Sub Form_Load() For i = 1 To 10 Bloque(i).X = Shape(i).Left Bloque(i).Y = Shape(i).Top Bloque(i).Height = Shape(i).Height Bloque(i).Width = Shape(i).Width Next i
c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height End Sub Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case vbKeyLeft Char.Left = Char.Left - 160 c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height LabelColision.Caption = m_System.MATH_IntersectRect(Bloque(i), c) 'Si hay colision, el char "no se mueve" If LabelColision.Caption = "Verdadero" Then Char.Left = Char.Left + 160 Label1.Caption = "Colision" End If Case vbKeyRight Char.Left = Char.Left + 160 c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height LabelColision.Caption = m_System.MATH_IntersectRect(Bloque(i), c)
If LabelColision.Caption = "Verdadero" Then Char.Left = Char.Left - 160 Label1.Caption = "Colision" End If Case vbKeyDown Char.Top = Char.Top + 160 c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height LabelColision.Caption = m_System.MATH_IntersectRect(Bloque(i), c) If LabelColision.Caption = "Verdadero" Then Char.Top = Char.Top - 160 Label1.Caption = "Colision" End If Case vbKeyUp Char.Top = Char.Top - 160 c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height
LabelColision.Caption = m_System.MATH_IntersectRect(Bloque(i), c) If LabelColision.Caption = "Verdadero" Then Char.Top = Char.Top - 160 Label1.Caption = "Colision" End If Case Else Exit Sub End Select End Sub
|
|
|
46
|
Programación / Programación Visual Basic / Re: Cambiar objeto a variable
|
en: 13 Octubre 2007, 22:37 pm
|
Mmmm... Lo expongo de otra manera. Estoy usando una librería llamada dx_lib32.dll (diseñada para videojuegos). Para definir las colisiones, es necesario colocar un objeto en el form(diseño) y una variable en el código, indicando en la variable el tamaño y posición de su objeto. Pongo el code para que sea mas fácil de entender. Option Explicit
Public m_System As New dx_System_Class
Dim Bloque1 As GFX_Rect Dim Bloque2 As GFX_Rect Dim Bloque3 As GFX_Rect Dim Char As GFX_Rect
Private Sub Form_Load()
Bloque1.X = Shape1.Left Bloque1.Y = Shape1.Top Bloque1.Height = Shape1.Height Bloque1.Width = Shape1.Width
Bloque2.X = Shape2.Left Bloque2.Y = Shape2.Top Bloque2.Height = Shape2.Height Bloque2.Width = Shape2.Width
Bloque3.X = Shape3.Left Bloque3.Y = Shape3.Top Bloque3.Height = Shape3.Height Bloque3.Width = Shape3.Width
End Sub
'...
Este código sólo detecta 3 bloques que impiden el paso, ahora imaginaros que quereis 100 bloques. Escribir eso sería un castigo. Pues preguntaba que si habria alguna manera de ahorrar código. Gracias. PD: Si no está claro, decidlo.
|
|
|
47
|
Programación / Programación Visual Basic / Re: Cambiar objeto a variable
|
en: 13 Octubre 2007, 13:27 pm
|
Option Explicit
Public m_System As New dx_System_Class
'Variable para Arrays Public i As Integer Public n As Integer
'Variables para el juego 'Muros Dim M(0 To 8) As GFX_Rect Dim Wall(0 To 8) As Shape
'Char Dim c As GFX_Rect
'Dimensiones de los muros y del char Const MuroWidth = 255 Const MuroHeight = 255 Const CharWidth = 255 Const CharHeight = 255
'Movimiento de Char Const MovChar = 240
Private Sub CargarNivel() For i = 0 To 8 Set Wall(i) = Muro(i) Next i
For i = 0 To 8 M(i).X = Muro(i).Left M(i).Y = Muro(i).Top M(i).Width = Muro(i).Width M(i).Height = Muro(i).Height Next i
c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height End Sub
Private Sub Form_Load()
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case vbKeyLeft Char.Left = Char.Left - MovChar c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height For i = 0 To 8 'Esto comprueba si hay colision LabelColision.Caption = m_System.MATH_IntersectRect(M(i), c) Next i 'Si hay colision, el char "no se mueve" If LabelColision.Caption = "Verdadero" Then Char.Left = Char.Left + MovChar Label1.Caption = "Sorry, not possible." End If Case vbKeyRight Char.Left = Char.Left + MovChar c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height For i = 0 To 8 LabelColision.Caption = m_System.MATH_IntersectRect(M(i), c) Next i If LabelColision.Caption = "Verdadero" Then Char.Left = Char.Left - MovChar Label1.Caption = "Sorry, not possible." End If Case vbKeyDown Char.Top = Char.Top + MovChar c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height For i = 0 To 8 LabelColision.Caption = m_System.MATH_IntersectRect(M(i), c) Next i If LabelColision.Caption = "Verdadero" Then Char.Top = Char.Top - MovChar Label1.Caption = "Sorry, not possible." End If Case vbKeyUp Char.Top = Char.Top - MovChar c.X = Char.Left c.Y = Char.Top c.Width = Char.Width c.Height = Char.Height For i = 0 To 8 LabelColision.Caption = m_System.MATH_IntersectRect(M(i), c) Next i If LabelColision.Caption = "Verdadero" Then Char.Top = Char.Top + MovChar Label1.Caption = "Sorry, not possible." End If Case Else Exit Sub End Select End Sub
Pero no va. Si hay por ejemplo 50 muros, el código sería enorme, por eso hago Muro(i). Se puede hacer de alguna manera?
|
|
|
|
|
|
|