[SOLVED]Added player graphix and get Bug report

Previous topic - Next topic

xxbastianxx

Hi, Bug Report: *** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.10.104 SN:409de90b - 2D, WIN32
"Player.gbas"(72) warning : probably unassigned variable : width
"Player.gbas"(73) warning : probably unassigned variable : height

  given: TPlayer
  wants: Anything
"My Jump and Run.gbas"(39) error : wrong argument type : LOADANIM, arg no: 2

     :nw: help




Code (glbasic) Select

[b]--> Jump and Run (Main Code)[/b]

SETCURRENTDIR("Media") // go to media files

GLOBAL PlayerImage%
PlayerImage = GENSPRITE()
LOADANIM "Plyer.png", Player, 32, 64


GLOBAL Player AS TPlayer //Spieler erstellen
GLOBAL Map AS TMap //Map erstellen




GOSUB Init
WHILE TRUE


   GOSUB Render
   GOSUB Update


   SHOWSCREEN

WEND

SUB Update:

Player.Update()
Map.Update ()


ENDSUB


SUB Render:

Map.Render ()
Player.Render()



ENDSUB


SUB Init:

Player.Init (100,100)
Map.Init("map0.txt")

ENDSUB


[b]Player[/b]

TYPE TPlayer

x; y
vx; vy //Vektor x,y
width%
height%
HP%
scrollx; scrolly

//...

FUNCTION Init: x, y, width% = 32, height% = 64

    self.x = x
    self.y = y
    self.vx = 0
    self.vy = 0


    self.width = width
    self.height = height

ENDFUNCTION




FUNCTION Update:

LOCAL scrwidth, scrheight
GETSCREENSIZE scrwidth, scrheight

//Schwerkraft
INC self.vy, 0.01


//Bewegung
IF KEY(203) THEN DEC self.vx, 1 //links
IF KEY(205) THEN INC self.vx, 1 //rechts
IF KEY(57) AND (Map.CollisionPoint(self.x + 1, self.y + self.height +1) OR Map.CollisionPoint(self.x + self.width -1, self.y + self.height +1)) THEN self.y = -4 //space


//trägheit
self.vx = self.vx* 0.5

LOCAL oldx, oldy
oldx = self.x
oldy = self.y

//grenze
IF self.vy > 8 THEN self.vy = 8
IF self.vy < -8 THEN self.vy = -8


//bewege & kollision
INC self.x, self.vx


IF Map.Collision(self.X+1, self.y+1, self.width-2, self.height-2)
self.x = oldx
ENDIF
INC self.y, self.vy

IF Map.Collision(self.X+1, self.y+1, self.width-2, self.height-2)
self.x = oldx
self.y = oldy

Map.scrollx = - self.x + scrwidth/2 + width/2
Map.scrolly = - self.y + scrheight/2 + height/2

ENDIF
ENDFUNCTION


FUNCTION Render:

   DRAWRECT self.x + 1 + Map.scrollx, self.y + Map.scrolly, self.width, self.height, RGB(255,0,0)
   DRAWSPRITE PlayerImage, 0, self.x + 1 + Map.scrollx, self.y + Map.scrolly 


ENDFUNCTION

ENDTYPE



[b]Map[/b]

CONSTANT tilesize = 64

//Spielkarte
TYPE TMap

data$[]
width% ; height%
scrollx; scrolly
Tilesize% //speichert Frames


FUNCTION Init: Name$

LOCAL chn% = GENFILE ()
LOCAL line$



IF OPENFILE ( chn, name$ ,  1) = FALSE THEN END

READLINE chn, line$
width.self = INTEGER (line$)

READLINE chn, line$
width.self = INTEGER (line$)

DIM self.datas[self.width][self.height]

WHILE ENDOFFILE (chn%) = FALSE
READLINE chn% , line$
LOCAL tile$[]

SPLITSTR (line$, tile$[], ",")

FOREACH tile IN tile$[]


x=0
FOREACH tile IN tile$ []
self.datas$ [x][y] = INTEGER(tile)
INC x
NEXT

INC y
WEND


ENDFUNCTION


FUNCTION Update:

ENDFUNCTION


FUNCTION Render:
FOR x = 0 TO self.width - 1
FOR y = 0 TO self.height -1
SELECT self.datas$[x][y]
CASE 0
CASE 1
DRAWRECT x*tilesize + self.scrollx, y*tilesize + scrolly, tilesize, tilesize , RGB(0, 255 ,0)
ENDSELECT
NEXT
NEXT
ENDFUNCTION




FUNCTION Collision%:  x, y, width, height

IF x >= 0 AND y >= 0 AND x < self.width*Tilesize AND y < self.height*Tilesize

x = INTEGER(x/Tilesize)
y = INTEGER(y/Tilesize)

IF self.Datas[x][y]
RETURN TRUE
ELSE
RETURN FALSE
ENDIF



ENDFUNCTION




FUNCTION CollisionPoint%: x, y
//eckpunkte
IF CollisionPoint(x, y) OR CollisionPoint(x, y + width) OR CollisionPoint(x, y + height) OR CollisionPoint(x + width, y + height)
RETURN TRUE
ELSE
RETURN FALSE

ENDIF

ENDFUNCTION


ENDTYPE


Ian Price

You are calling "Player" (in the LOADANIM code - "LOADANIM "Plyer.png", Player, 32, 64" before you have declared "Player" as a Global variable.

i presume you meant to use PlayerImage in the LOADANIM statement.
I came. I saw. I played.

xxbastianxx

Hey, thank you for your help (that was a mistake as well, but the real mistake is still in the code... just can't find it)

I've fixed the (72) (73) one with width, height ...

But I've seemed to miss the one for my image loading ...


I'd be very pleased if somebody could help me.

Kind Regards, Seb

fuzzy70

Quote from: Ian Price on 2013-Feb-22
You are calling "Player" (in the LOADANIM code - "LOADANIM "Plyer.png", Player, 32, 64" before you have declared "Player" as a Global variable.

i presume you meant to use PlayerImage in the LOADANIM statement.

Just as Ian said, you are using the 'Player' variable in your LOADANIM command which is not yet defined as either a GLOBAL or a LOCAL which will cause a compile error. Also just after that you then assign the PLAYER to a type which will not work as the type & the anim image are 2 different things.

Have you made any changes to the code since Ian's post & if so could you post it again. Also I notice there are
Code (glbasic) Select
[b] & [/b] in your posted code, did you add these after you pasted the code into your post, If so don't because as far as I know anything in-between codeblocks like bold/italic etc are ignored & causes extra work for people trying to help when they copy your code to see whats wrong.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

xxbastianxx

Ok, noted.
I'll post you my new code:


Main Code:

Code (glbasic) Select

SETCURRENTDIR("Media") // go to media files


GLOBAL Player AS TPlayer //Spieler erstellen
GLOBAL Map AS TMap //Map erstellen


GLOBAL PlayerImage%
PlayerImage = GENSPRITE()
LOADANIM "Plyer.png", Player, 32, 64      // <---- Swapped GLOBAL PlayerImage with GLOBAL Player AS TPlayer



GOSUB Init
WHILE TRUE


   GOSUB Render
   GOSUB Update


   SHOWSCREEN

WEND

SUB Update:

Player.Update()
Map.Update ()


ENDSUB


SUB Render:

Map.Render ()
Player.Render()



ENDSUB


SUB Init:

Player.Init (100,100)
Map.Init("map0.txt")

ENDSUB


xxbastianxx

#5
Quote from: Ian Price on 2013-Feb-22
You are calling "Player" (in the LOADANIM code - "LOADANIM "Plyer.png", Player, 32, 64" before you have declared "Player" as a Global variable.

i presume you meant to use PlayerImage in the LOADANIM statement.


So where exactly (and how exactly) do i declare Player ?  [Is it somethink like "GLOBAL Player = "Player.gbas" " ? ]
I've got the player as extra code ... Do you need it ?


Ian Price

You haven't understood what I or Lee said.

Quote
Code (glbasic) Select

PlayerImage = GENSPRITE()
LOADANIM "Plyer.png", Player, 32, 64      // <---- Swapped GLOBAL PlayerImage with GLOBAL Player AS TPlayer


You need to change your LOADANIM statement to -
Code (glbasic) Select

LOADANIM "Plyer.png", PlayerImage, 32, 64


The reason is that you have defined Player as a TYPE and PlayerImage is returning a sprite position value for your animated image.

Player and PlayerImage are two totally different things, as defined by your own code. Don't mix them up.
I came. I saw. I played.

xxbastianxx

aaah :) Thank You .... XD Sorry for the misunderstanding.

This can be closed