Skip to content

// Project: TopDownTemplate
// Created: 19-04-09
 
// show all errors
SetErrorMode(2)
 
// set window properties
SetWindowTitle("TopDownTemplate")
SetWindowSize(1024, 768, 0)
SetWindowAllowResize(1) // allow the user to resize the window
 
// set display properties
SetVirtualResolution(1024, 768) // doesn't have to match the window
SetOrientationAllowed(1, 1, 1, 1) // allow both portrait and landscape on mobile devices
SetSyncRate(60, 0) // 30fps instead of 60 to save battery
SetScissor(0, 0, 0, 0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1)
 
#insert "constants.agc"
#insert "game.scene"
game_setup()
 
global playerx as float
global playery as float
 
do
    playerx = GetSpriteX(game_player)
    playery = GetSpriteY(game_player)
     
    if GetRawKeyState(KEY_LEFT) = 1 and GetRawKeyState(KEY_RIGHT) = 0
        MoveLeft()
    endif
    if GetRawKeyState(KEY_RIGHT) = 1 and GetRawKeyState(KEY_LEFT) = 0
        MoveRight()
    endif
    if GetRawKeyState(KEY_UP) = 1 and GetRawKeyState(KEY_DOWN) = 0
        MoveUp()
    endif
    if GetRawKeyState(KEY_DOWN) = 1 and GetRawKeyState(KEY_UP) = 0
        MoveDown()
    endif
    SetSpritePosition(game_player, playerx, playery)
    game_sync()
    Print(ScreenFPS())
    Sync()
loop
 
function MoveUp()
    playery = playery - 4
    for x = game_walls.length to 0 step -1
        if RectsOverlap(playerx, playery, 64, 64, getSpriteX(game_walls[x]), getSpriteY(game_walls[x]), 64, 64) = 1
            playery = ( playery + 64 ) - mod(playery, 64)
        endif
    next   
endfunction
 
function MoveDown()
    playery = playery + 4
    for x = game_walls.length to 0 step -1
        if RectsOverlap(playerx, playery, 64, 64, getSpriteX(game_walls[x]), getSpriteY(game_walls[x]), 64, 64) = 1
            playery = playery - mod(playery, 64)
        endif
    next   
endfunction
 
function MoveRight()
    playerx = playerx + 4
    for x = game_walls.length to 0 step -1
        if RectsOverlap(playerx, playery, 64, 64, getSpriteX(game_walls[x]), getSpriteY(game_walls[x]), 64, 64) = 1
            playerx = playerx - mod(playerx, 64)
        endif
    next
endfunction
 
function MoveLeft()
    playerx = playerx - 4
    for x = game_walls.length to 0 step -1
        if RectsOverlap(playerx, playery, 64, 64, getSpriteX(game_walls[x]), getSpriteY(game_walls[x]), 64, 64) = 1
            playerx = ( playerx + 64 ) - mod(playerx, 64)
        endif
    next
endfunction
 
function RectsOverlap(x1, y1, w1, h1, x2, y2, w2, h2)
    value = 1
    If x1 >= (x2 + w2) Or (x1 + w1) <= x2 Then value = 0
    If y1 >= (y2 + h2) Or (y1 + h1) <= y2 Then value = 0
endfunction value

// Project: TrapDodge
// Created: 19-04-05

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle("TrapDodge")
SetWindowSize(1024, 768, 0)
SetWindowAllowResize(1) // allow the user to resize the window

// set display properties
SetVirtualResolution(1024, 768) // doesn't have to match the window
SetOrientationAllowed(1, 1, 1, 1) // allow both portrait and landscape on mobile devices
SetSyncRate(60, 0) // 30fps instead of 60 to save battery
SetScissor(0, 0, 0, 0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1)

#insert "constants.agc"
#insert "Game.scene"

img_Dave = LoadImage( "dave.png" )
spr_Dave = CreateSprite(img_Dave)
SetSpriteAnimation(spr_Dave, 32, 32, 12)

global hspeed as float = 0
global vspeed as float = 0
global WalkSpeed as float = 2.5
global Gravity as float = 0.3
global Move as integer

global KeyLeft as integer
global KeyRight as integer
global KeyJump as integer

global Player as integer
global PlayerX as float
global PlayerY as float

PlayerX = GetSpriteX(spr_Dave)
PlayerY = GetSpriteY(spr_Dave)

global DaveState as integer = 0



Game_setup()

do
	Game_sync()

	KeyLeft = GetRawKeyState(KEY_LEFT)
	KeyRight = GetRawKeyState(KEY_RIGHT)
	KeyJump = GetRawKeyState(KEY_CONTROL)
	
	
	Move = KeyRight - KeyLeft
	hspeed = Move * WalkSpeed
	vspeed = vspeed + Gravity
	
	if Move = 0 and DaveState = 0
//		SetSpriteFlip(spr_Dave, 0, 0)
		PlaySprite(spr_Dave, 6, 1, 7, 10 )
		DaveState = -1
	elseif Move = 1 and DaveState = -1
		SetSpriteFlip(spr_Dave, 0, 0)
		PlaySprite(spr_Dave, 8, 1, 1, 6)
		DaveState = 0
	elseif Move = -1 and DaveState = -1
		SetSpriteFlip(spr_Dave, 1, 0)
		PlaySprite(spr_Dave, 8, 1, 1, 6)
		DaveState = 0	
	endif

	
	for x = 0 to Game_CubeArray.length
		if RectsOverlap(PlayerX, PlayerY+1, 28, 32, GetSpriteX(Game_CubeArray[x]), GetSpriteY(Game_CubeArray[x]), 32, 32) and KeyJump = 1
			vspeed = -6.5
		endif
		//Horizontal Collision
		if RectsOverlap(PlayerX+hspeed,PlayerY, 28, 32, GetSpriteX(Game_CubeArray[x]), GetSpriteY(Game_CubeArray[x]), 32, 32)
			while not RectsOverlap(PlayerX+sin(hspeed),PlayerY, 32, 32, GetSpriteX(Game_CubeArray[x]), GetSpriteY(Game_CubeArray[x]), 32, 32)
				PlayerX = PlayerX + sin(hspeed)
			endwhile
			hspeed = 0
		endif
		//Vertical Collision
		if RectsOverlap(PlayerX, PlayerY+vspeed, 28, 32, GetSpriteX(Game_CubeArray[x]), GetSpriteY(Game_CubeArray[x]), 32, 32)
			while not RectsOverlap(PlayerX, PlayerY+sin(vspeed), 32, 32, GetSpriteX(Game_CubeArray[x]), GetSpriteY(Game_CubeArray[x]), 32, 32)
				PlayerY = PlayerY + sin(vspeed)
			endwhile
			vspeed = 0
		endif
	next
	
	PlayerX = PlayerX + hspeed
	PlayerY = PlayerY + vspeed
	
	SetSpritePosition(spr_Dave, PlayerX, PlayerY)
	print(Move)
	Sync()
loop

function RectsOverlap(x1, y1, w1, h1, x2, y2, w2, h2)
	value = 1
	If x1 >= (x2 + w2) Or (x1 + w1) <= x2 Then value = 0
	If y1 >= (y2 + h2) Or (y1 + h1) <= y2 Then value = 0
endfunction value

This will grab each sprite from a group array in AGK Studio and create a new type for each instance.

// Project: Zoikoids
// Created: 19-04-07
 
// show all errors
SetErrorMode(2)
 
// set window properties
SetWindowTitle("Zoikoids")
SetWindowSize(1024, 768, 0)
SetWindowAllowResize(1) // allow the user to resize the window
 
// set display properties
SetVirtualResolution(1024, 768) // doesn't have to match the window
SetOrientationAllowed(1, 1, 1, 1) // allow both portrait and landscape on mobile devices
SetSyncRate(60, 0) // 30fps instead of 60 to save battery
SetScissor(0, 0, 0, 0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1)
 
#insert "game.scene"
game_setup()
 
img_Ligher = LoadImage( "Ligher.png" )
global player as integer
global playerx as float
global playery as float
 
playerx = GetVirtualWidth() / 2
playery = GetVirtualHeight() - GetImageHeight(img_Ligher) - 64
player = CreateSprite(img_Ligher)
SetSpriteAnimation(player, 32, 32, 4)
SetSpriteScale(player, 2, 2)
playsprite(player)
 
type Zoik
    id as integer
    x as float
    y as float
endtype
global ZoikList as Zoik[]
 
for x = game_Zoikoids.length to 0 step -1
    local z as zoik
    z.id = CreateSprite(GetSpriteImageID(game_Zoikoids[x]))
    SetSpriteScale(z.id, 2, 2)
    z.x = GetSpriteX(game_Zoikoids[x])
    z.y = GetSpriteY(game_Zoikoids[x])
    ZoikList.insert(z)
next
 
for x = game_Zoikoids.length to 0 step -1
    DeleteSprite(game_Zoikoids[x])
next
game_Zoikoids.length = -1
 
 
for x = ZoikList.length to 0 step -1
    SetSpritePosition(Zoiklist[x].id, ZoikList[x].x, ZoikList[x].y)
next
 
 
 
do
 
     
    setspriteposition(player, playerx, playery)
    game_sync()
    Print(ScreenFPS())
    Sync()
loop