[Erledigt]Fehlermeldung:"Illegal memory access" be

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

 

Coral

Betreff: [Erledigt]Fehlermeldung:"Illegal memory access" be

BeitragMo, Okt 05, 2009 21:55
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo Leute,
Ich habe mir das Buch Game Programming For Teens gekauft. Da ist ein PingPong Quelltext für Blitzmax drin, den ich für Blitz3D umgeschrieben habe. Dann wollte ich den Text so verändern, dass man gegen einen Freund spielen kann. Wenn ich das Spiel aber starte, kriege ich die Fehlermeldung: "Illegal memory access" und das Programm geht sofort wieder zu. Hier mein Code:

Code: [AUSKLAPPEN]

;Set up graphics mode
Graphics 800,600

;Seed the random generator (make random numbers actually random)
SeedRnd(MilliSecs())

;Create a back buffer
SetBuffer BackBuffer()
;Set the handle to the center of images
AutoMidHandle True 


Const HUMAN_SPEED = 7 ;The human;s max speed
Const COMPUTER_SPEED = 6 ;The computer;s max speed
Const X_RANDOM_FACTOR = 2 ;The variance of the x speed after colliding with something
Const Y_RANDOM_FACTOR = 1 ;The variance of the y speed after colliding with something
;The ball;s speed at the beginning of a level
Const LEVEL_START_XV_MIN = 3
Const LEVEL_START_XV_MAX = 6
Const LEVEL_START_YV_MIN = -8
Const LEVEL_START_YV_MAX = 8

;TYPES
;The player type: both the human and the opponent
Type Tplayer
   Field y# ;The vertical position of the player
   Field score#
End Type   

;The ball type: for the ball
Type Tball
   Field x#
   Field y#
;xv and yv are the velocity variables
   Field xv#
   Field yv#   
End Type

;IMAGES
;The picture of the human player
Global player1image = LoadImage("player1.bmp")   

;The picture of the computer player
Global player2image = LoadImage("player2.bmp")

;The picture of the ball
Global ballimage = LoadImage("ball.bmp") ;Load the ball image


;TYPE INITIALIZATION

;Create a ball
Global ball.Tball = New Tball
;Create the human
Global player1.Tplayer = New Tplayer
;Create the computer
Global player2.Tplayer = New Tplayer 



;INITIALIZATION
Locate 400,300
Print "Ready...Set";Wait for one second
Flip
Delay(1000)
Locate 420,330
Print "GO!!!"
Flip
;Delay for 1/5 of a second
Delay(200)

;Initialize the level
InitializeLevel()


;Set inital scores
player1\score = 0
player2\score = 0

;MAIN LOOP
While Not KeyHit(1)

;Clear the screen
Cls

;Draw the ball
DrawImage (ballimage,ball\x,ball\y)
;Draw the human
DrawImage (player1image, 60, player1\y)
;Draw the computer
DrawImage (player2image, 740, player2\y)

;Test what user pressed
TestKeyboard()
TestKeyboard2()
;What should AI do?
TestAI()
;Draw the HUD
DrawScore()

Flip

Delay 20

Wend ;END OF MAIN LOOP

;FUNCTIONS
;INITIALIZELEVEL()
;Sets up starting values
Function InitializeLevel()

;Put ball in center of the screen
ball\x = 400
ball\y = 300

;Make the ball move in a random direction
ball\xv = Rand(LEVEL_START_XV_MIN, LEVEL_START_XV_MAX)
ball\yv = Rand(LEVEL_START_YV_MIN, LEVEL_START_YV_MAX)

;Place the players in their correct position
player2\y = 300
player1\y = 300
End Function


;DRAWSCORE()
;Draws the HUD in the top right
Function DrawScore()
;Write the human score
Locate 700, 0
Print "Player 1: " + player1\score
;Write the computer;s score
Locate 700, 30
Print "Player 2: " + player2\score
End Function

;TESTKEYBOARD()
;Moves player up and down based on keyboard
Function TestKeyboard()

;If player presses up, move him up
If KeyDown(200) ; Pfeiltaste hoch
   player1\y = player1\y - HUMAN_SPEED
EndIf

;If player presses down, move him down
If KeyDown(208) ; Pfeiltaste runter
   player1\y = player1\y + HUMAN_SPEED
End If

;if player presses Pause, pause the game
If KeyHit(25) ; P
   ;make screen blank
   Cls
   
   Locate 400,300
   Print "Press 'P' to Unpause Game"   
   Flip
   
   ;wait for player to unpause
   While Not KeyHit(25) ; P
   Wend

EndIf

End Function


Function TestKeyboard2() ; player 2


;If player presses up, move him up
If KeyDown(17) ; W
   player1\y = player2\y - HUMAN_SPEED
EndIf

;If player presses down, move him down
If KeyDown(31) ; S
   player1\y = player2\y + HUMAN_SPEED
EndIf

End Function





;TESTAI()
;Updates ball and score and enemy
Function TestAI()
 

If player1\y <= 0 Then player1\y = 0
   
If player1\y >= 600 Then player1\y = 600   
   
If player2\y <= 0 Then player2\y = 0
   
If player2\y >= 600 Then player2\y = 600         
   
;If ball hits human player, reflect it away from him and vary its velocity and direction
If ImagesCollide(ballimage,ball\x,ball\y,0,player1image,60,player1\y,0)
   ball\xv = -ball\xv + Rand(-X_RANDOM_FACTOR,X_RANDOM_FACTOR)
   ball\yv = ball\yv + Rand(-Y_RANDOM_FACTOR,Y_RANDOM_FACTOR)
   
;If ball hits computer, reflect it away from computer and vary its velocity and direction
ElseIf ImagesCollide(ballimage,ball\x,ball\y,0,player2image,740,player2\y,0)
   ball\xv = -ball\xv + Rand(-X_RANDOM_FACTOR,X_RANDOM_FACTOR)
   ball\yv = ball\yv + Rand(-Y_RANDOM_FACTOR,Y_RANDOM_FACTOR)
   
;If ball hits top wall, reflect it downward
ElseIf ball\y <= 0 
   ball\xv = ball\xv + Rand (-X_RANDOM_FACTOR,X_RANDOM_FACTOR)
   ball\yv = -ball\yv + Rand (-Y_RANDOM_FACTOR,Y_RANDOM_FACTOR) 
   
;If ball hits bottom wall, reflect it upward
ElseIf ball\y >= 600
   ball\xv = ball\xv + Rand (-X_RANDOM_FACTOR,X_RANDOM_FACTOR) 
   ball\yv = -ball\yv + Rand (-Y_RANDOM_FACTOR,Y_RANDOM_FACTOR)
   
;if ball hits left wall, computer has scored so computer gets one more point
ElseIf ball\x <= 0 
   player2\score = player2\score + 1   ;computer scores
   Locate 400,300
   Print "Player 2 Scores!!!"
   Flip
   ;wait two seconds
   Delay(2000)
   
   ;reset level
   InitializeLevel()
   
;If ball hits right wall, human scored so give him a point
ElseIf ball\x >= 800
   player1\score = player1\score + 1   ;human scores
   Locate 400, 300
   Print "Player 1 Scores!!!"
   Flip
   ;wait 2 secs
   Delay(2000)
   ;reset level
   InitializeLevel()
EndIf
   
   ;update ball;s position on screen
   ball\x = ball\x + ball\xv
   ball\y = ball\y + ball\yv
   
End Function
  • Zuletzt bearbeitet von Coral am Di, Okt 06, 2009 12:46, insgesamt einmal bearbeitet
 

Coral

Betreff: Halb erledigt

BeitragMo, Okt 05, 2009 22:16
Antworten mit Zitat
Benutzer-Profile anzeigen
Oh die Fehlermeldung hat sich schon erledigt... aus irgendeinem Grund funktioniert das bei mir mit den relativen Pfaden nicht, daran lags. Aber da könnt ihr mir ja vielleicht sagen was falsch ist^^

TimBo

BeitragMo, Okt 05, 2009 22:56
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi,

sind die Bilder auch im selben Ordner wie die Exe bzw. die bb Datei ?

Sonst fällt mir nichts, außer dieser 1 Sek wartezeit am Anfang, was total unnötig ist, auf.

Grüße
TimBo
mfg Tim Borowski // CPU: Ryzen 2700x GPU: Nvidia RTX 2070 OC (Gigabyte) Ram: 16GB DDR4 @ 3000MHz OS: Windows 10
Stolzer Gewinner des BCC 25 & BCC 31
hat einen ersten Preis in der 1. Runde beim BWInf 2010/2011 & 2011/12 mit BlitzBasic erreicht.
 

Coral

BeitragDi, Okt 06, 2009 10:57
Antworten mit Zitat
Benutzer-Profile anzeigen
*gegen den Kopf schlag* die Bilder hießen bei mir player.bmp und player1.bmp. Deswegen konnte er player2 nicht laden^^ Aber danke für die Hilfe

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group