Hello!
I hope someone could help me with this one... After over a year period of not being able to code with AppGameKit, I finally have a chance to do so, and I've started to work on a simple Pong project.
I have structured my game into several files, and now I'm having a problem with creating a sprite. I created a UDT for Paddle object with random ID, and I am trying to assign the generated spriteID from createSprite(0) call to Paddle.ID. My program compiles without errors but when I try to execute the game, the following error pops up: "Sprite xxx does not exist at line 7 in game_control.agc". I'll paste some snippets to demonstrate my program flow.
// main.agc
rem Includes
#include "setup_game.agc"
#include "globals.agc"
#include "constants.agc"
#include "game_control.agc"
#include "draw_control.agc"
// Initialize game environment
setupGame()
gameObjects_init()
remstart
MAIN LOOP
remend
do
// ...
loop
// setup_game.agc
function setupGame()
// Initialize global variables and game objects
globals_init()
// Initialize constant variables
constants_init()
// ...
endfunction
// globals.agc
// User Defined Types
type GamePaddle
id as integer
width as integer
height as integer
x as float // Center of the sprite
y as float // Center of the sprite
endtype
remstart
Game globals
remend
function globals_init()
// Variable for game states
global g_currentGameState = 0
// Init game paddles
global g_PlayerPaddle as GamePaddle
//global g_AIPaddle as GamePaddle
endfunction
// game_controls.agc
remstart
Initialize game objects
remend
function gameObjects_init()
// Set PlayerPaddle values
g_PlayerPaddle.id = createSprite(0)
g_PlayerPaddle.width = 5
g_PlayerPaddle.height = 15
g_PlayerPaddle.x = 90.0
g_PlayerPaddle.y = 50.0
// Set PlayerPaddle sprite and its properties
setSpriteColor(g_PlayerPaddle.id, 10, 10, 200, 180)
setSpriteOffset(g_PlayerPaddle.id, g_PlayerPaddle.width/2, g_PlayerPaddle.height/2)
setSpritePositionByOffset(g_PlayerPaddle.id, g_PlayerPaddle.x, g_PlayerPaddle.y)
endfunction
remstart
Update game objects and their values
remend
function updateGameObjects()
// ...
endfunction
I hope I provided enough information for you guys and can help me spot what I'm missing here!
Thanks in advance!