Okay, I have put the educational software on hold for a while and have decided to do something a bit more fun in making a platform game
This is in part due to Crazy Programmer and Conjured Entertainment giving me lot's of inspiration with their projects.
First off, I am not fully sure of where this is going to go as I haven't made my mind up with a title, theme or graphic style yet!
and I might also do an educational title at the same time as this yet lol but right now I am maybe thinking some sort of pixel retro style?
Anyway I decided to have a mess with the percentage system as I decided to do my next project in this style due to not being happy with the black bars on the apps on different devices.
If you saw my other post for this you will see that first it is not easy to think this way in %age's, especially being an old school programmer! It just doesn't seem natural but I think I am just about getting my head around it now
This is where I got up to anyway:
// Project: Voxel Platform
// Created: Spectre
// ######################################## Set up the screen
SetSyncRate(30,0)
SetOrientationAllowed(0,0,1,1)
screenWidth# = GetMaxDeviceWidth()
screenHeight# = GetMaxDeviceHeight()
aspect# = screenWidth#/screenHeight#
SetDisplayAspect(-1)
displayLeft# = GetScreenBoundsLeft()
displayRight# = GetScreenBoundsRight()
displayTop# = GetScreenBoundsTop()
displayBottom# = GetScreenBoundsBottom()
displayWidth# = displayRight# - displayLeft#
displayHeight# = displayBottom# - displayTop#
displayCentreX# = displayWidth# * 0.5
displayCentreY# = displayHeight# * 0.5
SetScissor( displayLeft#, displayTop#, displayRight#, displayBottom# )
// ###########################################################
// ######################################## Set up pixel percentages
onePercentX# = screenWidth#/100.0
onePercentY# = screenHeight#/100.0
xPixel# = 100.0/screenWidth#
yPixel# = 100.0/screenHeight#
// ###########################################################
// ######################################## Set up joystick and buttons
joyStick = 1
joyStickSizeX# = xPixel# * 250.0
joyStickSizeY# = joyStickSizeX# * aspect#
joyStickCentreX# = joyStickSizeX# * 0.5
joyStickCentreY# = joyStickSizeY# * 0.5
AddVirtualJoystick(joyStick, 99.0 - joyStickCentreX# , 99.0 - joyStickCentreY# , joyStickSizeX#)
SetVirtualJoystickAlpha(joyStick, 60.0, 110.0)
button1 = 1
button2 = 2
buttonSizeX# = xPixel# * 150.0
buttonSizeY# = buttonSizeX# * aspect#
buttonCentreX# = buttonSizeX# * 0.5
buttonCentreY# = buttonSizeY# * 0.5
AddVirtualButton(button1, 1.0 + buttonCentreX#, 99.0 - buttonCentreY#, buttonSizeX#)
AddVirtualButton(button2, 2.0 + buttonSizeX# + buttonCentreX#, 99.0 - buttonCentreY#, buttonSizeX#)
SetVirtualButtonText(button1,"1")
SetVirtualButtonText(button2,"2")
SetVirtualButtonAlpha(button1, 110.0)
SetVirtualButtonAlpha(button2, 110.0)
// ###########################################################
// ######################################## Set up game preferences
xSpeed# = xPixel# * 4.0
ySpeed# = (screenHeight#/screenWidth#) * aspect#
Dim lvl_map[10,10]
// ###########################################################
// ######################################## Load media
#constant numberLvlBlocks = 57
gosub loadLevelImages
backImage = LoadImage("0.png")
backSprite = CreateSprite(backImage)
SetSpriteSize(backSprite, 100.0, 100.0)
SetSpritePosition(backSprite, 0.0, 0.0)
blockSizeX# = xPixel# * (onePercentX# * 10)
blockSizeY# = yPixel# * (onePercentY# * 10)
xPos# = 0.0
yPos# = 0.0
blockImage1 = LoadImage("1.png")
blockImage2 = LoadImage("2.png")
blockImage3 = LoadImage("3.png")
blockImage4 = LoadImage("4.png")
gosub level_1
//SetSpriteSize(blockSprite, blockSizeX#, blockSizeY#)
//SetSpritePosition(blockSprite, xPos#, yPos#)
// ###########################################################
SetPrintColor(0,0,0)
do
//xPos# = xPos# + xSpeed#
//yPos# = xPos# * ySpeed#
//SetSpritePosition(blockSprite, xPos#, yPos#)
//gosub printSettings
Sync()
loop
printSettings:
Print ("Screen Width = " + Str(screenWidth#))
Print ("Screen Height = " + Str(screenHeight#))
Print ("Display Width = " + Str(displayWidth#))
Print ("Display Height = " + Str(displayHeight#))
Print ("Aspect = " + Str(aspect#))
Print ("Number of X pixels in 1% = " + Str(onePercentX#))
Print ("Number of Y pixels in 1% = " + Str(onePercentY#))
Print ("Size in % 1 X pixel = " + Str(xPixel#))
Print ("Size in % 1 Y pixel = " + Str(yPixel#))
Print ("JoyStick X: "+ Str(GetVirtualJoystickX(joyStick)))
Print ("JoyStick Y: "+ Str(GetVirtualJoystickY(joyStick)))
Print ("Button 1: "+ Str(GetVirtualButtonState(button1)))
Print ("Button 2: "+ Str(GetVirtualButtonState(button2)))
Print ("X Speed = " + Str(xSpeed#))
Print ("Y Speed = " + Str(ySpeed#))
Print ("FPS = " + Str(ScreenFPS()))
return
// ######################################## Level data and build
// 0 = Blank square
// 1 = Platform Block 1
level_1:
lvl$= "0000000000"
lvl$=lvl$ + "F000000000"
lvl$=lvl$ + "3300u00000"
lvl$=lvl$ + "6003300000"
lvl$=lvl$ + "00000000Q0"
lvl$=lvl$ + "0000000330"
lvl$=lvl$ + "00R0700000"
lvl$=lvl$ + "0033330003"
lvl$=lvl$ + "0006600036"
lvl$=lvl$ + "3333333366"
gosub build_lvl
return
build_lvl:
textPos = 0
for y = 1 to 10
for x = 1 to 10
textPos = textPos + 1
blockNUM$ = Mid(lvl$,textPos,1)
if blockNUM$ <> "0"
for i = 1 to numberLvlBlocks
if blockNUM$ = lvlBlock[i].sLevelSection
blockSprite=CreateSprite(lvlBlock[i].iImage)
endif
next i
SetSpriteSize(blockSprite, blockSizeX#, blockSizeY#)
lvl_map[x,y]=blockSprite
SetSpritePosition( lvl_map[x,y], (x-1) * blockSizeX#, (y-1) * blockSizeY# )
else
lvl_map[x,y]=0
endif
next x
next y
return
// ###########################################################
// ######################################## Levels
loadLevelImages:
Type level_block_Type
iImage as integer
sLevelSection as string
Endtype
lvlBlock as level_block_Type[numberLvlBlocks]
level_texture_image = LoadImage("level_blocks.png")
lvlBlock[1].iImage = LoadSubImage(level_texture_image, "brick_grey.png")
lvlBlock[2].iImage = LoadSubImage(level_texture_image, "brick_red.png")
lvlBlock[3].iImage = LoadSubImage(level_texture_image, "dirt_grass.png")
lvlBlock[4].iImage = LoadSubImage(level_texture_image, "dirt_sand.png")
lvlBlock[5].iImage = LoadSubImage(level_texture_image, "dirt_snow.png")
lvlBlock[6].iImage = LoadSubImage(level_texture_image, "dirt.png")
lvlBlock[7].iImage = LoadSubImage(level_texture_image, "fence_stone.png")
lvlBlock[8].iImage = LoadSubImage(level_texture_image, "fence_wood.png")
lvlBlock[9].iImage = LoadSubImage(level_texture_image, "grass_brown.png")
lvlBlock[10].iImage = LoadSubImage(level_texture_image, "grass_tan.png")
lvlBlock[11].iImage = LoadSubImage(level_texture_image, "grass_top.png")
lvlBlock[12].iImage = LoadSubImage(level_texture_image, "grass1.png")
lvlBlock[13].iImage = LoadSubImage(level_texture_image, "grass2.png")
lvlBlock[14].iImage = LoadSubImage(level_texture_image, "grass3.png")
lvlBlock[15].iImage = LoadSubImage(level_texture_image, "grass4.png")
lvlBlock[16].iImage = LoadSubImage(level_texture_image, "gravel_dirt.png")
lvlBlock[17].iImage = LoadSubImage(level_texture_image, "gravel_stone.png")
lvlBlock[18].iImage = LoadSubImage(level_texture_image, "greysand.png")
lvlBlock[19].iImage = LoadSubImage(level_texture_image, "greystone_ruby_alt.png")
lvlBlock[20].iImage = LoadSubImage(level_texture_image, "greystone_ruby.png")
lvlBlock[21].iImage = LoadSubImage(level_texture_image, "greystone_sand.png")
lvlBlock[22].iImage = LoadSubImage(level_texture_image, "greystone.png")
lvlBlock[23].iImage = LoadSubImage(level_texture_image, "ice.png")
lvlBlock[24].iImage = LoadSubImage(level_texture_image, "lava.png")
lvlBlock[25].iImage = LoadSubImage(level_texture_image, "mushroom_brown.png")
lvlBlock[26].iImage = LoadSubImage(level_texture_image, "mushroom_red.png")
lvlBlock[27].iImage = LoadSubImage(level_texture_image, "mushroom_tan.png")
lvlBlock[28].iImage = LoadSubImage(level_texture_image, "redsand.png")
lvlBlock[29].iImage = LoadSubImage(level_texture_image, "redstone_emerald_alt.png")
lvlBlock[30].iImage = LoadSubImage(level_texture_image, "redstone_emerald.png")
lvlBlock[31].iImage = LoadSubImage(level_texture_image, "redstone_sand.png")
lvlBlock[32].iImage = LoadSubImage(level_texture_image, "redstone.png")
lvlBlock[33].iImage = LoadSubImage(level_texture_image, "rock_moss.png")
lvlBlock[34].iImage = LoadSubImage(level_texture_image, "rock.png")
lvlBlock[35].iImage = LoadSubImage(level_texture_image, "sand.png")
lvlBlock[36].iImage = LoadSubImage(level_texture_image, "snow.png")
lvlBlock[37].iImage = LoadSubImage(level_texture_image, "stone_browniron_alt.png")
lvlBlock[38].iImage = LoadSubImage(level_texture_image, "stone_browniron.png")
lvlBlock[39].iImage = LoadSubImage(level_texture_image, "stone_coal_alt.png")
lvlBlock[40].iImage = LoadSubImage(level_texture_image, "stone_coal.png")
lvlBlock[41].iImage = LoadSubImage(level_texture_image, "stone_diamond_alt.png")
lvlBlock[42].iImage = LoadSubImage(level_texture_image, "stone_diamond.png")
lvlBlock[43].iImage = LoadSubImage(level_texture_image, "stone_dirt.png")
lvlBlock[44].iImage = LoadSubImage(level_texture_image, "stone_gold_alt.png")
lvlBlock[45].iImage = LoadSubImage(level_texture_image, "stone_gold.png")
lvlBlock[46].iImage = LoadSubImage(level_texture_image, "stone_grass.png")
lvlBlock[47].iImage = LoadSubImage(level_texture_image, "stone_iron_alt.png")
lvlBlock[48].iImage = LoadSubImage(level_texture_image, "stone_iron.png")
lvlBlock[49].iImage = LoadSubImage(level_texture_image, "stone_sand.png")
lvlBlock[50].iImage = LoadSubImage(level_texture_image, "stone_silver_alt.png")
lvlBlock[51].iImage = LoadSubImage(level_texture_image, "stone_silver.png")
lvlBlock[52].iImage = LoadSubImage(level_texture_image, "stone_snow.png")
lvlBlock[53].iImage = LoadSubImage(level_texture_image, "stone.png")
lvlBlock[54].iImage = LoadSubImage(level_texture_image, "water.png")
lvlBlock[55].iImage = LoadSubImage(level_texture_image, "wheat_stage1.png")
lvlBlock[56].iImage = LoadSubImage(level_texture_image, "wheat_stage2.png")
lvlBlock[57].iImage = LoadSubImage(level_texture_image, "wheat_stage3.png")
lvlBlock[1].sLevelSection = "1"
lvlBlock[2].sLevelSection = "2"
lvlBlock[3].sLevelSection = "3"
lvlBlock[4].sLevelSection = "4"
lvlBlock[5].sLevelSection = "5"
lvlBlock[6].sLevelSection = "6"
lvlBlock[7].sLevelSection = "7"
lvlBlock[8].sLevelSection = "8"
lvlBlock[9].sLevelSection = "9"
lvlBlock[10].sLevelSection = "A"
lvlBlock[11].sLevelSection = "B"
lvlBlock[12].sLevelSection = "C"
lvlBlock[13].sLevelSection = "D"
lvlBlock[14].sLevelSection = "E"
lvlBlock[15].sLevelSection = "F"
lvlBlock[16].sLevelSection = "G"
lvlBlock[17].sLevelSection = "H"
lvlBlock[18].sLevelSection = "I"
lvlBlock[19].sLevelSection = "J"
lvlBlock[20].sLevelSection = "K"
lvlBlock[21].sLevelSection = "L"
lvlBlock[22].sLevelSection = "M"
lvlBlock[23].sLevelSection = "N"
lvlBlock[24].sLevelSection = "O"
lvlBlock[25].sLevelSection = "P"
lvlBlock[26].sLevelSection = "Q"
lvlBlock[27].sLevelSection = "R"
lvlBlock[28].sLevelSection = "S"
lvlBlock[29].sLevelSection = "T"
lvlBlock[30].sLevelSection = "U"
lvlBlock[31].sLevelSection = "V"
lvlBlock[32].sLevelSection = "W"
lvlBlock[33].sLevelSection = "X"
lvlBlock[34].sLevelSection = "Y"
lvlBlock[35].sLevelSection = "Z"
lvlBlock[36].sLevelSection = "a"
lvlBlock[37].sLevelSection = "b"
lvlBlock[38].sLevelSection = "c"
lvlBlock[39].sLevelSection = "d"
lvlBlock[40].sLevelSection = "e"
lvlBlock[41].sLevelSection = "f"
lvlBlock[42].sLevelSection = "g"
lvlBlock[43].sLevelSection = "h"
lvlBlock[44].sLevelSection = "i"
lvlBlock[45].sLevelSection = "j"
lvlBlock[46].sLevelSection = "k"
lvlBlock[47].sLevelSection = "l"
lvlBlock[48].sLevelSection = "m"
lvlBlock[49].sLevelSection = "n"
lvlBlock[50].sLevelSection = "o"
lvlBlock[51].sLevelSection = "p"
lvlBlock[52].sLevelSection = "q"
lvlBlock[53].sLevelSection = "r"
lvlBlock[54].sLevelSection = "s"
lvlBlock[55].sLevelSection = "t"
lvlBlock[56].sLevelSection = "u"
lvlBlock[57].sLevelSection = "v"
return
// ###########################################################
I have now expanded it a bit and am making a level editor and game all in one.
I use a simple tag at the start of the program to either start the map editor or game:
// Use gameMode$ "editor" for level editor or "game" to play the game
gameMode$ = "game"
if gameMode$ = "editor"
So far the levels are static and only one screen in size but I plan to expand this to scroll the levels and be large in size.
In editor mode you can start making a level on a blank screen or you can load a previous created level and edit that if you want. Once done I just press the "S" key to save the level.
The loading and saving of the levels is very simple as they are saved as a .txt file, which I might rename to .dat later, not sure yet.
This is how they were stored originally in the code itself using 10 x 10 blocks:
level_1:
lvl$= "0000000000"
lvl$=lvl$ + "F000000000"
lvl$=lvl$ + "3300u00000"
lvl$=lvl$ + "6003300000"
lvl$=lvl$ + "00000000Q0"
lvl$=lvl$ + "0000000330"
lvl$=lvl$ + "00R0700000"
lvl$=lvl$ + "0033330003"
lvl$=lvl$ + "0006600036"
lvl$=lvl$ + "3333333366"
gosub build_lvl
return
but now in the .txt file they are stored like this:
0 0 0 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 0 3 3 0 0 u 0 0 0 0 0 G 0 0 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 F 0 0 0 0 0 0 0 0 3 3 0 0 0 R 0 Y 0 0 0 0 D 0 0 h h h h 0 0 0 h 0 0 0 f g 0 0 0 h i h h h h h h h h i j
and now I read the levels in all at once at the start and store them like this:
// ######################################## Load all Levels
readLevels:
for i = 0 to totalLevels
OpenToRead(1, "lvl_" + Str(i) + ".txt")
for n = 1 to lvlX * lvlY
if n = 1
l$ = ReadString(1)
else
l$ = l$ + ReadString(1)
endif
next n
lvl$[i] = l$
CloseFile ( 1 )
next i
return
I might have to change this when the levels get much bigger but for now it works well and fast as the levels are built like this:
// ######################################## Build Levels
build_lvl:
textPos = 0
for y = 1 to lvlY
for x = 1 to lvlX
textPos = textPos + 1
blockNUM$ = Mid(lvl$[lvlNUM],textPos,1)
if blockNUM$ <> "0"
for i = 1 to numberLvlBlocks
if blockNUM$ = lvlBlock[i].sLevelSection
blockSprite=CreateSprite(lvlBlock[i].iImage)
endif
next i
SetSpriteSize(blockSprite, blockSizeX#, blockSizeY#)
lvl_map[x,y]=blockSprite
SetSpritePosition( lvl_map[x,y], (x-1) * blockSizeX#, (y-1) * blockSizeY# )
else
lvl_map[x,y]=0
endif
next x
next y
return
Game mode so far simply has the level loaded with a virtual joystick and 2 buttons for fire and jump as I haven't even got a player on there to move yet
So that's where I am at after coding for a couple of days.
What do you think? Any ideas, feedback, comments etc are welcome
Here are a couple of quick video clips showing you where I am up to so far, nothing special.....yet haha
Game Mode:
Level Editor Mode: