My Enemies Are Flashing :(

Blitz3D Forums/Blitz3D Programming/My Enemies Are Flashing :(

matthews_30(Posted 2006) [#1]
you need 3 images, a player, an enemy and a hud (diablo like), i am trying to re-use several codes from the forum and adapting it to work all together. everything was working until i create the enemies :(

"always the bad guys..."

this is the code (veru much commented)

;This script is edited in Brain Editor Pro - v1.0.8 DEMO
; Prototipo rpg, Diablo 2 like game :P
; iniciado el 12/05/2006

AppTitle "Prueba de RPG por Batman!"

Graphics 640,480,0,2 ;ponemos el modo grafico en 640x480 con profundidad 0 modo 2 (ventana)

;Constantes
Const BufferWidth=640, BufferHeight=480

;Constantes de estado
vagar=1
perseguir=2
atacar=3


;Globals
;Global mouseImage=loadimage("punteroMouse.bmp")

;Globals para el jugador
Global ultimoClickX=320
Global ultimoClickY=240
Global playerX=320
Global playerY=240
Global imgPlayer=LoadImage("cristiano.png")
playerVel#=1
;MaskImage imgPlayer,255,0,255

;Globals para enemigos
Global imgEnemigo=LoadImage("archer_m_01_nvo.PNG")
;Global imgEnemigoV=LoadImage("archer_caminando.PNG") ;enemigo vagando
;Global imgEnemigoP=LoadImage("archer_persiguiendo.PNG") ;enemigo persiguiendo
;Global imgEnemigoA=LoadImage("archer_atacando.PNG") ;enemigo atacando




;Variables varias
splashScreen=loadimage("splashScreen.bmp"); pantalla de bienvenida

;ahora creamos una imagen negra donde dibujaremos
Global pictureBuffer=createimage(bufferwidth,bufferheight)

Setbuffer Backbuffer()

;musica de fondo
musicaFondo=playmusic("musicaFondo.mp3")

;pantalla de bienvenida
DrawImage(splashScreen,0,0) ;parte desde la posicion 0,0
Flip
Delay 2000
;freeimage splashScreen
;splashScreen=0
cls

Text 230,240,"Entrando al nivel 1"
Flip
Delay 2000

StopChannel musicaFondo ; detenemos la reproduccion de la musica de introduccion

;main loop
While not keyhit(1)
Cls

;dibujamos el HUD
hud_image=LoadImage("hud.png") ;el HUD
MaskImage hud_image,255,0,255
DrawImage(hud_image,0,350)
;Flip


If Mousedown(1) Then ultimoClickX=Mousex() ultimoClickY=MouseY()

; If ultimoClick <= 593 or ultimoClickY <= 371 then

DrawImage imgPlayer,playerX-32,playerY-32

If playerX < ultimoClickX then playerX = playerX+1

If playerx > ultimoClickX then playerX = playerX-1

If playerY < ultimoClickY then playerY = playerY+1

If playerY > ultimoClickY then playerY = playerY-1

; End If

; nuestro enemigo aparece en escena

enemyX#=rand(0,640)
enemyY#=rand(0,480)
enemyVel=.5
enemyEstado=vagar
dist_perseguir=100
dist_atacar=20
pos_VagarX=rand(0,640)
pos_VagarY=rand(0,480)
MaskImage imgPlayer,255,0,255


; movimientos del enemigo
; obtenemos la distancia entre ambos
dis# = Sqr(((playerX-enemyX)*(playerX-enemyX)) + ((playerY-enemyY)*(playerY-enemyY)))

; inteligencia artificial
If enemyEstado=vagar and dis#<dist_perseguir then enemyEstado=perseguir
If enemyEstado=perseguir and dis#<dist_perseguir then enemyEstado=vagar
If enemyEstado=perseguir and dis#<dist_atacar then enemyEstado=atacar
If enemyEstado=atacar and dis#>dist_atacar then enemyEstado=perseguir

; ejecutar acciones segun estado actual
If enemyEstado=vagar
If enemyX<pos_VagarX then enemyX=enemyX+enemyVel
If enemyX>pos_VagarX then enemyX=EnemyX-enemyVel
If enemyY>pos_VagarY then enemyY=enemyY-enemyVel
If enemyY<pos_VagarY then enemyY=enemyY+enemyVel
dis# = Sqr(((pos_VagarX-enemyX)*(pos_VagarX-enemyX)) + ((pos_VagarY-enemyY)*(pos_VagarY-enemyY)))
if dis#<50 then
pos_VagarX=rand(0,640)
pos_VagarY=rand(0,480)
end if
end if

If enemyEstado=perseguir
If enemyX<playerX Then enemyX=enemyX+enemyVel
If enemyX>playerX Then enemyX=enemyX-enemyVel
If enemyY>playerY Then enemyY=enemyY-enemyVel
If enemyY<playerY Then enemyY=enemyY+enemyVel
EndIf

If enemyEstado=atacar
If enemyX<playerX Then enemyX=enemyX+enemyVel
If enemyX>playerX Then enemyX=enemyX-enemyVel
If enemyY>playerY Then enemyY=enemyY-enemyVel
If enemyY<playerY Then enemyY=enemyY+enemyVel
EndIf

; ahora dibujamos el enemigo

drawimage imgEnemigo,enemyX,EnemyY

If estate=roam Then drawimage imgEnemigo,enemyX,EnemyY
If estate=chase Then drawimage imgEnemigo,enemyX,EnemyY
If estate=attack Then drawimage imgEnemigo,enemyX,EnemyY


; imprimimos la posicion actual de nuestro personaje
Text 0,0,"Actual posicion X del jugador: "+ultimoClickX
Text 0,12,"Actual posicion Y del jugador: "+ultimoClickY

;pasamos la pagina (flip)
Flip
Wend ;fin del main loop

End


matthews_30(Posted 2006) [#2]
oops, i forget to mention the spalshScreen and the mp3 sound for it.

please any comment may help...


jhocking(Posted 2006) [#3]
My Enemies Are Flashing

That means you defeated them and they are about to disappear from the screen.


Ross C(Posted 2006) [#4]
You really need to TAB your code man. It makes it so much easier to read.


Ross C(Posted 2006) [#5]
These lines here, might be your problem...

DrawImage imgEnemigo,enemyX,EnemyY

If estate=roam Then DrawImage imgEnemigo,enemyX,EnemyY
If estate=chase Then DrawImage imgEnemigo,enemyX,EnemyY
If estate=attack Then DrawImage imgEnemigo,enemyX,EnemyY


Your drawing the image. Then, doing some checks, and drawing the same image, regardless of the outcomes of your if statements


jhocking(Posted 2006) [#6]
On a more serious note, this bit of code seems a tad redundant:

drawimage imgEnemigo,enemyX,EnemyY

If estate=roam Then drawimage imgEnemigo,enemyX,EnemyY
If estate=chase Then drawimage imgEnemigo,enemyX,EnemyY
If estate=attack Then drawimage imgEnemigo,enemyX,EnemyY


Now I'm not sure why that would cause flashing, but I assume "imgEnemigo" is the flashing graphic you are referring to. If not, please be more specific in describing your problem.

EDIT: He beat me to it. Basically, delete those three If lines.


Ross C(Posted 2006) [#7]
Hehehe :OP slow coach ;) The commenting doesn't help much i'm afraid, cause it's in a different language, but try our suggestion out, see what happens.


matthews_30(Posted 2006) [#8]
ok, my code is tabbed (indented) but i dont know how to do int when posting.

second, i think the problem is that the enemy is been generated randomly every time the cicle runs.

i made a test moving all the enemy variables out of the main loop but the enemy stay freeze in the first position.

matt.


Ross C(Posted 2006) [#9]
So, are they still flashing? If you could provide the media, we could further help you :o)


matthews_30(Posted 2006) [#10]
i have the media, how can i send it?

do you have an email?

my email is oscargarin@...

B!


Ross C(Posted 2006) [#11]
.


matthews_30(Posted 2006) [#12]
sent!


Ross C(Posted 2006) [#13]
Ok, these lines here:

	enemyX#=rand(0,640)
	enemyY#=rand(0,480)


You constantly giving the enemy a random position. You will need to have an X and Y variable holding the enemies position and increment these to move it.

The problem you will run into, is when you want to create more enemies. You should look into types for this.


Ross C(Posted 2006) [#14]
Unfortunatly, it's hard to try and put things into your code, because of the variable name being in your native language. But, you will need to find a way of moving the enemy and changing it's direction. What about something simple, like moving the enemy in a direction until he hits a wall?

Your flashing is caused by the constant moving of the enemies position.


matthews_30(Posted 2006) [#15]
i thoght it was the problem, but i tried to take it out of the mail loop, but if failed, any idea about how to make it work?


Ross C(Posted 2006) [#16]
Well, you need to give the enemy co-ords to start. So, set it's co-ords, before the main loop starts. How do you want your enemy to move?


matthews_30(Posted 2006) [#17]
i think the problem is that the coords are given in the main loop. i tried to move it outside the mail loop and declaring as global, but the enemy stay in the same place, no flashing nor enemy movement :(

i will try to re-create the whole code, and i will try to use variables in english.

many thanks for all.


Ross C(Posted 2006) [#18]
Well, you will need to move the enemy within the code. That is probably the hardest part of creating these games. You will need to create code for moving the enemy. Maybe have some variables to move it or something :o) Your last attempt at moving the enemy, involved you randomly positioned the enemy at different spots on the screen. It makes it look like it's flashing. It's not :o) Just moving randomly to different spots on the screen.


RGR(Posted 2006) [#19]
.

Last edited 2012


matthews_30(Posted 2006) [#20]
Excellent!

many thanks exactly what i needed to know!

thank you, very much!

B!