The higher i set the player speed, the more i can see this effect. With speed 1 it's barely visible, but this movement is just too slow for the game.
Here is the code:
// Project: Starfighter
// Created: 2015-04-29
// define booleans
#constant TRUE 1
#constant FALSE 0
// define keys
#constant KEY_ESC 27
#constant KEY_CTRL 17
#constant KEY_LEFT 37
#constant KEY_RIGHT 39
// define screen size
#constant SCREEN_W 320
#constant SCREEN_H 240
// define GameObject
type T_GameObject
id as Integer
img as Integer
width as Integer
height as Integer
x as Float
y as Float
speed as Float
endtype
// set window properties
SetWindowTitle( "Starfighter" )
SetWindowSize(SCREEN_W, SCREEN_H, TRUE)
// set display properties
SetVirtualResolution(SCREEN_W, SCREEN_H)
// turn vertical sync on
SetVSync(TRUE)
SetClearColor(8, 8, 64)
SetBorderColor(8, 8, 8)
// set player properties
global player as T_GameObject
player.img = LoadImage("starfighter.png")
SetImageMagFilter(player.img, 0)
player.width = GetImageWidth(player.img)
player.height = GetImageHeight(player.img)
player.x = (SCREEN_W - player.width) * 0.5
player.y = SCREEN_H - (player.height * 2)
player.speed = 5
// set weapon properties
global weapon as T_GameObject
weapon.img = LoadImage("bullet.png")
SetImageMagFilter(weapon.img, 0)
weapon.width = GetImageWidth(weapon.img)
weapon.height = GetImageHeight(weapon.img)
weapon.y = player.y - weapon.height
weapon.speed = 3
// create weapon magazine
global mag as T_GameObject[]
// initialize the game before playing
InitGame()
// main loop
while GetRawKeyPressed(KEY_ESC) <> 1
UpdateGame()
RenderGame()
Print(str(mag.length))
Sync()
endwhile
function InitGame()
// create sprites
player.id = CreateSprite(player.img)
SetSpritePosition(player.id, player.x, player.y)
endfunction
function UpdateGame()
UpdatePlayer()
UpdateWeapon()
endfunction
function RenderGame()
RenderPlayer()
RenderWeapon()
endfunction
function UpdatePlayer()
if GetRawKeyState(KEY_LEFT) = 1
dec player.x, player.speed
elseif GetRawKeyState(KEY_RIGHT) = 1
inc player.x, player.speed
endif
if GetRawKeyPressed(KEY_CTRL) = 1
CreateBullet()
endif
endfunction
function UpdateWeapon()
if mag.length <> -1
for i = 0 to mag.length
dec mag[i].y, mag[i].speed
if mag[i].y < 30
DeleteSprite(mag[i].id)
mag.remove(i)
endif
next i
endif
endfunction
function RenderPlayer()
SetSpritePosition(player.id, player.x, player.y)
endfunction
function RenderWeapon()
if mag.length <> -1
for i = 0 to mag.length
SetSpritePosition(mag[i].id, mag[i].x, mag[i].y)
next i
endif
endfunction
function CreateBullet()
weapon.id = CreateSprite(weapon.img)
weapon.x = player.x + player.width * 0.5
mag.insert(weapon)
n = mag.length
SetSpritePosition(mag[n].id, mag[n].x, mag[n].y)
endfunction
AGK2 Tier 1 / GameGuru / ProMotion 6.5