|
Post by shadow008 on Jul 31, 2009 15:42:45 GMT -5
hmmm ive had a similar problem. ive tried something like that but it didnt work... but i was using 3d and that might not apply unless it was 2d. w/e
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 31, 2009 15:47:08 GMT -5
Zombies(X)
X = the number of zombies I want, correct?
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Jul 31, 2009 16:03:30 GMT -5
I would have something like this for the structure: struc Szombie dim alive dim sprite dim x dim y endstruc
then you just need to define a array of those structures: dim Szombie Zombies(X)
then when creating the sprites you do something like this: Zombies(X).Sprite = newsprite(zom)
and each time you want to move the zombie sprite: bindsprite(Zombies(X).Sprite)
'code that moves that sprite sprmovex, sprmovey etc
i hope you can understand how i would do it. i'm not the best at explaning things . I'm not good at these "piece by piece" instructions, I like to see it all compiled into one big thing, so here, something like this? Textmode(text_buffered) dim textures (TexStripFrames("data\street.png")-1) = LoadTexStrip ("data\street.png")
data 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0
dim tiles(10)(10), x, y for y = 0 to 10 for x = 0 to 10 read tiles(x)(y) next next
dim tile = NewTileMap(textures) SprSetTiles(tiles) SprSetZOrder(1) SprSetSize(200,200)
'------------------------
dim xPlayer, wWin, yPlayer, hWin, alive
ResizeSpriteArea(Windowwidth(),WindowHeight())
xPlayer=Windowwidth()/2 yPlayer=WindowHeight()/2 wWin=Windowwidth()/2 hWin=Windowheight()/2 alive= true dim Mark(ImageStripFrames("data\strain.png") - 1) Mark = LoadImageStrip("data\strain.png") dim MarkSpr = NewSprite(Mark(0)) SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true)
struc Szombie dim alive dim sprite dim x dim y endstruc
x = Windowheight() y = Windowwidth()
dim Zom(ImageStripFrames("data\zombie.png") - 1) Zom = LoadImageStrip("data\zombie.png") dim ZomSpr = NewSprite(Zom(0)) SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true)
dim Szombie Zombies(3) Zombies(3).Sprite = newsprite(zom)
dim Speed# = 5 dim zSpeed# = 3 '------------------------------------
while (true) bindsprite(markspr) if alive then if ScanKeyDown (VK_LEFT) then xPlayer=xPlayer-Speed# SprSetTexture(mark(1)) elseif ScanKeyDown (VK_RIGHT) then xPlayer=xPlayer+Speed# SprSetTexture(mark(3))
elseif ScanKeyDown(VK_UP) then yPlayer=yPlayer-Speed# SprSetTexture(mark(0)) elseif ScanKeyDown(VK_DOWN) then yPlayer=yPlayer+Speed# SprSetTexture(mark(2)) else SPRsettexture(mark(0)) endif endif
SprCameraSetPos(xPlayer-wWin,yPlayer-hWin) SprSetPos(xPlayer,yPlayer)
bindsprite(zomspr)
if zombies(3).alive then if xPlayer > zombies(3).x then Zombies(3).x = Zombies(3).x + zSpeed# SprSetTexture(zom(3)) elseif xPlayer < Zombies(3).X then Zombies(3).X = Zombies(3).X - zSpeed# SprSetTexture(zom(1)) endif
if yPLayer > Zombies(3).Y then Zombies(3).Y =Zombies(3).Y + zSpeed# SprSetTexture(zom(0)) elseif Yplayer < Zombies(3).Y then Zombies(3).Y = Zombies(3).Y - zSpeed# SprSetTexture(zom(2))
endif
if Zombies(3).X = xplayer then alive = false endif if Zombies(3).Y = yplayer then alive = false endif SprSetPos(Zombies(3).X,Zombies(3).Y) endif
DRAWTEXT()
if alive = false then locate 10,19 print "game over" endif wend '------------------------ I know the zombie doesn't move, but am I on the right track, at least? Feel free to change things around.
|
|
|
Post by James :) (aka Madcow) on Aug 1, 2009 3:11:46 GMT -5
Ok multiple zombies work atm . Textmode(text_buffered) dim textures (TexStripFrames("data\street.png")-1) = LoadTexStrip ("data\street.png")
data 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0
dim tiles(10)(10), x, y for y = 0 to 10 for x = 0 to 10 read tiles(x)(y) next next
dim tile = NewTileMap(textures) SprSetTiles(tiles) SprSetZOrder(1) SprSetSize(200,200)
'------------------------
dim xPlayer, wWin, yPlayer, hWin, alive
ResizeSpriteArea(Windowwidth(),WindowHeight())
xPlayer=Windowwidth()/2 yPlayer=WindowHeight()/2 wWin=Windowwidth()/2 hWin=Windowheight()/2 alive= true dim Mark(ImageStripFrames("data\strain.png") - 1) Mark = LoadImageStrip("data\strain.png") dim MarkSpr = NewSprite(Mark(0)) SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true)
struc Szombie dim alive dim sprite dim x dim y endstruc
x = Windowheight() y = Windowwidth()
dim Zom(ImageStripFrames("data\zombie.png") - 1) Zom = LoadImageStrip("data\zombie.png") SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true) const numberofzombies = 3 dim i dim Szombie Zombies(numberofzombies-1) for i = 0 to arraymax(Zombies) Zombies(i).sprite = newsprite(zom) Zombies(i).alive = true Zombies(i).x = rnd()%1000 Zombies(i).y = rnd()%1000 next
dim Speed# = 5 dim zSpeed# = 3 '------------------------------------
while (true) bindsprite(markspr) if alive then if ScanKeyDown (VK_LEFT) then xPlayer=xPlayer-Speed# SprSetTexture(mark(1)) elseif ScanKeyDown (VK_RIGHT) then xPlayer=xPlayer+Speed# SprSetTexture(mark(3))
elseif ScanKeyDown(VK_UP) then yPlayer=yPlayer-Speed# SprSetTexture(mark(0)) elseif ScanKeyDown(VK_DOWN) then yPlayer=yPlayer+Speed# SprSetTexture(mark(2)) else SPRsettexture(mark(0)) endif endif
SprCameraSetPos(xPlayer-wWin,yPlayer-hWin) SprSetPos(xPlayer,yPlayer)
for i = 0 to arraymax(Zombies)
bindsprite(Zombies(i).sprite)
if zombies(i).alive then if xPlayer > zombies(i).x then Zombies(i).x = Zombies(i).x + zSpeed# SprSetTexture(zom(3)) elseif xPlayer < Zombies(i).X then Zombies(i).X = Zombies(i).X - zSpeed# SprSetTexture(zom(1)) endif
if yPLayer > Zombies(i).Y then Zombies(i).Y =Zombies(i).Y + zSpeed# SprSetTexture(zom(0)) elseif Yplayer < Zombies(i).Y then Zombies(i).Y = Zombies(i).Y - zSpeed# SprSetTexture(zom(2))
endif
if Zombies(i).X = xplayer then alive = false endif if Zombies(i).Y = yplayer then alive = false endif SprSetPos(Zombies(i).X,Zombies(i).Y) endif
next
DRAWTEXT()
if alive = false then locate 10,19 print "game over" endif wend '------------------------
this contains what i suggested in my earlyer post i noticed that you get a gameover when you arent touching a zombie :S
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 1, 2009 13:19:50 GMT -5
Ahh, I see exactly what you did there.
Except the random numbers
So rnd()%1000 ? It can be any number between WindowHeight() and 1000% above that?
Also, I hope you don't feel like you're doing my work for me. I wasn't really expecting all of this, I was just asking if I was on the right track, but now you've given me a greater understanding of structures.
Thank you
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 1, 2009 13:32:29 GMT -5
What I'll work on now, is getting some proper collision detection between the players and the zombies.
"if Xplayer = Xzombie then game over" doesn't really work, since you could be on the same X axis 50 feet away and still lose.
I could do something like "if X zombie = Windowheight()/2 then game over"
Or would that not work since Xplayer IS Windowheight()/2...
I'm just thinking out loud here, don't mind me.
Something YOU can help me with is getting transparency to work. I've tried "SetTransparentTex (255,255,255) " or whatever the correct command is, but that did nothing.
|
|
|
Post by James :) (aka Madcow) on Aug 1, 2009 14:39:16 GMT -5
Ahh, I see exactly what you did there. Except the random numbers So rnd()%1000 ? It can be any number between WindowHeight() and 1000% above that? any number between 0 and 1000, you can improve on how the game chooses to put the zombies as it sometimes puts them on the player at the beginning. i mainly added random positions there, purely to see if multiple zombies were working. ill look into transparency.
|
|
|
Post by DJLinux on Aug 1, 2009 14:41:13 GMT -5
you need an PlayField(xSize-1,ySize-1) now only a zombie or the player can stay on one field. now if you move one zombie to 4,4 and on 4,4 is the player then PlayerLifes=PlayerLifes-1 if PlayerLifes=0 then GameOver
the playfield coords can be any if you need the player in the middle of the screen move the SpriteCamera to Player Position not the Player to the Center of Screen.
You know what i'm say ;-)
|
|
|
Post by James :) (aka Madcow) on Aug 1, 2009 14:51:16 GMT -5
SetTexTransparentCol(255,255,255)
should work for transparency but i tried it on your code and it didnt work maybe the white background of your sprite isnt 255,255,255 but thats all i can think of. lol my knowlage of the sprite engine is being tested atm.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 1, 2009 15:57:48 GMT -5
you need an PlayField(xSize-1,ySize-1) now only a zombie or the player can stay on one field. now if you move one zombie to 4,4 and on 4,4 is the player then PlayerLives=PlayerLives-1 if PlayerLives=0 then GameOver the playfield coords can be any if you need the player in the middle of the screen move the SpriteCamera to Player Position not the Player to the Center of Screen. You know what i'm say ;-) Lives? What is this, a first gen game? We don't use Lives here!! That's just a little gaming humor there. You ever notice that in this generation of games, there are no lives, only checkpoints and loading saved games... I'll add that, but first I have a question What does the "-1" mean after xSize? I've never known what the "-1" means after things. I know it means "minus one" but why it's necessary, I don't know. EDIT: I'm having trouble using PlaySize I dimmed xSize to equal 29, (the radius of my sprite, not counting the white space) and did the same to ySize Then I tried this: dim PlaySize(xSize-1,ySize-1)
Textmode(text_buffered) SetTexTransparentCol(255,255,255) dim textures (TexStripFrames("data\street.png")-1) = LoadTexStrip ("data\street.png")
data 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0 data 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 0
dim tiles(10)(10), x, y for y = 0 to 10 for x = 0 to 10 read tiles(x)(y) next next
dim tile = NewTileMap(textures) SprSetTiles(tiles) SprSetZOrder(1) SprSetSize(200,200)
'------------------------
dim xPlayer, wWin, yPlayer, hWin, alive, xSize, ySize
ResizeSpriteArea(Windowwidth(),WindowHeight()) xSize = 29 ySize = 29 dim Playfield(xSize-1,ySize-1) xPlayer=Windowwidth()/2 yPlayer=WindowHeight()/2 wWin=Windowwidth()/2 hWin=Windowheight()/2 alive= true dim Mark(ImageStripFrames("data\strain.png") - 1) Mark = LoadImageStrip("data\strain.png") dim MarkSpr = NewSprite(Mark(0)) SprSetZOrder(-1) SprSetAnimSpeed(1) SprSetParallax(true)
struc Szombie dim alive dim sprite dim x dim y endstruc
x = Windowheight() y = Windowwidth()
dim Zom(ImageStripFrames("data\zombie.png") - 1) Zom = LoadImageStrip("data\zombie.png") SprSetZOrder(1) SprSetAnimSpeed(1) SprSetParallax(true)
const numberofzombies = 3 dim i dim Szombie Zombies(numberofzombies-1) for i = 0 to arraymax(Zombies) Zombies(i).sprite = newsprite(zom) Zombies(i).alive = true Zombies(i).x = rnd()%1000 Zombies(i).y = rnd()%1000 next
dim Speed# = 5 dim zSpeed# = 1 '------------------------------------
while (true) bindsprite(markspr) if alive then if ScanKeyDown (VK_LEFT) then xPlayer=xPlayer-Speed# SprSetTexture(mark(1)) elseif ScanKeyDown (VK_RIGHT) then xPlayer=xPlayer+Speed# SprSetTexture(mark(3))
elseif ScanKeyDown(VK_UP) then yPlayer=yPlayer-Speed# SprSetTexture(mark(0)) elseif ScanKeyDown(VK_DOWN) then yPlayer=yPlayer+Speed# SprSetTexture(mark(2)) else SPRsettexture(mark(0)) endif endif
SprCameraSetPos(xPlayer-wWin,yPlayer-hWin) SprSetPos(xPlayer,yPlayer)
for i = 0 to arraymax(Zombies)
bindsprite(Zombies(i).sprite)
if zombies(i).alive then if xPlayer > zombies(i).x then Zombies(i).x = Zombies(i).x + zSpeed# SprSetTexture(zom(3)) elseif xPlayer < Zombies(i).X then Zombies(i).X = Zombies(i).X - zSpeed# SprSetTexture(zom(1)) endif
if yPLayer > Zombies(i).Y then Zombies(i).Y =Zombies(i).Y + zSpeed# SprSetTexture(zom(2)) elseif Yplayer < Zombies(i).Y then Zombies(i).Y = Zombies(i).Y - zSpeed# SprSetTexture(zom(0))
endif
if Zombies(i).X = xplayer then alive = false endif if Zombies(i).Y = yplayer then alive = false endif SprSetPos(Zombies(i).X,Zombies(i).Y) endif
next
DRAWTEXT()
if alive = false then locate 10,19 print "game over" endif wend '------------------------Here's it added, but now I don't quite know how to proceed. I want it to so this: "If Zombies are inside the playfield, gameover" And I want the playfield to be my player You don't have to do my work for me, just guide me. I am but an arrow in your bow of knowledge. Wet clay, in your skillful hands.
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 1, 2009 16:03:07 GMT -5
SetTexTransparentCol(255,255,255)
should work for transparency but i tried it on your code and it didnt work maybe the white background of your sprite isnt 255,255,255 but thats all i can think of. lol my knowlage of the sprite engine is being tested atm. Maybe. I made it with GIMP, but I think it knows the difference between off-white and white. I'm not sure either.
|
|
|
Post by James :) (aka Madcow) on Aug 1, 2009 16:33:10 GMT -5
appears as 255,255,255 with me so i dunno :S
|
|
|
Post by Pizzasgood on Aug 1, 2009 19:22:12 GMT -5
I don't know about that specific case because I haven't looked through your code. But in general, things tend to have a "-1" because in the computer world a lot of things start with 0 instead of 1. So if you have an array of five items, it has entries with indexes ranging from 0 to 4. So when dealing with arrays, you use something like total_items - 1 in order to refer to the last item.
|
|
|
Post by DJLinux on Aug 1, 2009 19:42:26 GMT -5
sorry i meant PlayerLifes not PlayerLi ves and Pizzagood wrote it if you need an array with 100x100 items it would be an Array(99,99) this is why you can read often const MAX_X=100 const MAX_Y=100 dim Array(MAX_X-1,MAX_Y-1) ' same as 0 to 99,0 to 99 and this for y=0 to MAX_Y-1 for x=0 to MAX_X-1 Array(x,y)=value next next
|
|
OW
Posts a bit
Posts: 100
|
Post by OW on Aug 1, 2009 20:24:31 GMT -5
Ok, thanks.
|
|