Isome
Hallo allerseits
Ich habe aus Interesse eine kleine Engine geschrieben womit sich eine 2d Karte isometrisch darstellen lässt. Die Umrechnung von Mauskoordinaten in die Kartenkoordinaten funktioniert auch.
Somit lassen sich kleine Aufbauspiele realisieren
Wenn ihr Spaß hab könnt ihr damit ein bißchen rumspielen und verbesserungswünschen äußern (bugs natürlich auch ).
Bilder
[Blockierte Grafik: https://picload.org/image/rcwwrraw/img2.jpg]
[Blockierte Grafik: https://picload.org/image/rcwwrror/img1.jpg]
Funktionen
- Fenstegröße änderbar
- tilegröße änderbar
- kartengröße änderbar
- kartenbewegung mit maus
- kartenbewegung mit tastatur
- Mausklick auf Karte (Koordinatenumrechnung)
Quellcode
Isome
AutoIt
;isome globals
;fenstergröße
Global $window_width
Global $window_height
;tileset größen
Global $tile_width
Global $tile_height
;karteneigenschaften
Global $game_map_width
Global $game_map_height
Global $game_map_x
Global $game_map_y
Global $game_map
;beweggeschwindigkeit und überlauf
Global $game_map_smooth_x
Global $game_map_smooth_y
Global $game_map_speed
;maus
Global $mouse_x
Global $mouse_y
;game_resize()
Func game_resize($width, $height)
$window_width = $width
$window_height = $height
EndFunc ;==>game_resize
;game_position()
Func game_position($x, $y)
$mouse_x = $x
$mouse_y = $y
EndFunc ;==>game_position
;game_init()
Func game_init($width, $height, $tile_size, $map_width, $map_height, $map_x, $map_y, $default_value)
game_resize($width, $height)
$tile_width = $tile_size * 2
$tile_height = $tile_size
$game_map_width = $map_width
$game_map_height = $map_height
$game_map_x = $map_x
$game_map_y = $map_y
$game_map_smooth_x = 0
$game_map_smooth_y = 0
$game_map_speed = $tile_height / 4
Dim $game_map[$game_map_width][$game_map_height]
;clear game_map
game_map_fill($default_value)
EndFunc ;==>game_init
;game_map_fill()
func game_map_fill($value)
For $x = 0 To $game_map_width - 1
For $y = 0 To $game_map_height - 1
$game_map[$x][$y] = $value
Next
Next
EndFunc
;game_input()
Func game_input($moveable_keyboard = False, $moveable_mouse = False, $clickable = False, $click_event = False)
Local $diffx
Local $diffy
Local $mx
Local $my
Local $map_field
Local $border = 6
;pfeiltastenbewegung
If $moveable_keyboard Then
If _IsPressed(25) Then
$game_map_smooth_x -= $game_map_speed
ElseIf _IsPressed(27) Then
$game_map_smooth_x += $game_map_speed
EndIf
If _IsPressed(26) Then
$game_map_smooth_y -= $game_map_speed
ElseIf _IsPressed(28) Then
$game_map_smooth_y += $game_map_speed
EndIf
EndIf
;mausbewegung
If $moveable_mouse Then
If $mouse_x <= $border Then
$game_map_smooth_x -= $game_map_speed
ElseIf $mouse_x >= $window_width - $border * 2 Then
$game_map_smooth_x += $game_map_speed
EndIf
If $mouse_y <= $border Then
$game_map_smooth_y -= $game_map_speed
ElseIf $mouse_y >= $window_height - $border * 2 Then
$game_map_smooth_y += $game_map_speed
EndIf
EndIf
;überlauf
If $moveable_keyboard Or $moveable_mouse Then
If $game_map_smooth_x <= 0 - $tile_width Then
$game_map_x -= 1
$game_map_y -= 1
$game_map_smooth_x = 0
ElseIf $game_map_smooth_x >= $tile_width Then
$game_map_x += 1
$game_map_y += 1
$game_map_smooth_x = 0
EndIf
If $game_map_smooth_y <= 0 - $tile_height Then
$game_map_x += 1
$game_map_y -= 1
$game_map_smooth_y = 0
ElseIf $game_map_smooth_y >= $tile_height Then
$game_map_x -= 1
$game_map_y += 1
$game_map_smooth_y = 0
EndIf
EndIf
;maustatse gedrückt
If $clickable Then
If _IsPressed(1) Or _IsPressed(2) Then
$x = $game_map_x
$y = $game_map_y
$diffx = Int(($mouse_x + $tile_width * 2 + $game_map_smooth_x) / $tile_width)
$diffy = Int(($mouse_y + $tile_height * 2 + $game_map_smooth_y) / $tile_height)
$x += $diffx
$y += $diffx
$y += $diffy
$x -= $diffy
$mx = Mod(($mouse_x + $tile_width * 2 + $game_map_smooth_x), $tile_width)
$my = Mod(($mouse_y + $tile_height * 2 + $game_map_smooth_y), $tile_height)
If $mx < $tile_width / 2 Then
If $my < $tile_height / 2 And $mx * 0.5 < ($tile_height / 2) - $my Then
$y -= 1
ElseIf $mx * -0.5 > ($tile_height / 2) - $my Then
$x -= 1
EndIf
Else
$mx -= $tile_width / 2
If $my < $tile_height / 2 And $mx * -0.5 < 0 - $my Then
$x += 1
ElseIf $mx * 0.5 > ($tile_height) - $my Then
$y += 1
EndIf
EndIf
$map_field = game_map_get($x, $y)
If $map_field Then
$click_event($x, $y, $map_field)
EndIf
EndIf
EndIf
EndFunc ;==>game_input
;game_map_get()
Func game_map_get($x, $y)
If $x >= 0 And $y >= 0 And $x < $game_map_width And $y < $game_map_height Then
Return $game_map[$x][$y]
EndIf
Return False
EndFunc ;==>game_map_get
;game_map_set()
Func game_map_set($x, $y, $value)
If $x >= 0 And $y >= 0 And $x < $game_map_width And $y < $game_map_height Then
$game_map[$x][$y] = $value
Return True
EndIf
Return False
EndFunc ;==>game_map_set
;game_draw()
Func game_draw($buffer, $event_draw)
Local $draw_left
Local $draw_top = -$tile_height * 2 - $game_map_smooth_y
Local $game_map_x_start = $game_map_x
Local $game_map_y_start = $game_map_y
Local $n = 0
Local $x
Local $y
Local $map_field
Local $tile
Local $scaled_h
Do
$x = $game_map_x_start
$y = $game_map_y_start
$draw_left = -$tile_width * 2 - $game_map_smooth_x
If Mod($n, 2) <> 0 Then
$draw_left += $tile_width / 2
$game_map_x_start -= 1
Else
$game_map_y_start += 1
EndIf
$n += 1
Do
$map_field = game_map_get($x, $y)
If $map_field Then
$tile = $event_draw($x, $y, $map_field)
$scaled_h = ($tile_width / _GDIPlus_ImageGetWidth($tile)) * _GDIPlus_ImageGetHeight($tile)
_GDIPlus_GraphicsDrawImageRect($buffer, $tile, $draw_left, $draw_top - $scaled_h + $tile_height, $tile_width, $scaled_h)
EndIf
$x += 1
$y += 1
$draw_left += $tile_width
Until $draw_left >= $window_width
$draw_top += $tile_height / 2
Until $draw_top >= $window_height + $tile_height * 2
EndFunc ;==>game_draw
Alles anzeigen
Isome Demo
AutoIt
#include <gdiplus.au3>
#include <misc.au3>
#include <windowsconstants.au3>
#include <guiconstants.au3>
#include <isome.au3>
$screen_width = 800
$screen_height = 600
$gui = GUICreate("Isome Demo", $screen_width, $screen_height, -1, -1, $WS_MINIMIZEBOX + $WS_SIZEBOX)
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($gui)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($screen_width, $screen_height, $graphics)
$buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
$tile1 = _GDIPlus_ImageLoadFromFile("tile1.png")
$tile2 = _GDIPlus_ImageLoadFromFile("tile2.png")
GUISetState()
$pos = WinGetClientSize($gui)
$screen_width = $pos[0]
$screen_height = $pos[1]
;game_init($width,$height,$tile_size,$map_width,$map_height,$map_x,$map_y,$default_value)
game_init($screen_width, $screen_height, 64, 50, 50, 10, 10, 1)
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $GUI_EVENT_RESIZED
$pos = WinGetClientSize($gui)
$screen_width = $pos[0]
$screen_height = $pos[1]
game_resize($screen_width, $screen_height)
_GDIPlus_GraphicsClear($buffer)
_GDIPlus_BitmapDispose($bitmap)
_GDIPlus_GraphicsClear($graphics)
$graphics = _GDIPlus_GraphicsCreateFromHWND($gui)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($screen_width, $screen_height, $graphics)
$buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
EndSwitch
$info = GUIGetCursorInfo()
If Not @error Then
game_position($info[0], $info[1])
EndIf
;game_input($moveable_keyboard = false,$moveable_mouse = false,$clickable = false,$click_event = false)
game_input(True, True, True, click_event)
_GDIPlus_GraphicsClear($buffer, 0xffffffff)
;game_draw($buffer,$event_draw)
game_draw($buffer, draw_event)
_GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0)
Sleep(5)
WEnd
Func click_event($x, $y, $value)
If _IsPressed(1) Then
game_map_set($x, $y, 2)
ElseIf _IsPressed(2) Then
game_map_set($x, $y, 1)
EndIf
EndFunc ;==>click_event
Func draw_event($x, $y, $value)
If $value = 1 Then
Return $tile1
ElseIf $value = 2 Then
Return $tile2
EndIf
EndFunc ;==>draw_event
Alles anzeigen
Isome Snake
AutoIt
#include <gdiplus.au3>
#include <misc.au3>
#include <windowsconstants.au3>
#include <guiconstants.au3>
#include <isome.au3>
$screen_width = 840
$screen_height = 400
$gui = GUICreate("Isome Snake", $screen_width, $screen_height)
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($gui)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($screen_width, $screen_height, $graphics)
$buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
$tile1 = _GDIPlus_ImageLoadFromFile("tile_snake1.png")
$tile2 = _GDIPlus_ImageLoadFromFile("tile_snake2.png")
$tile3 = _GDIPlus_ImageLoadFromFile("tile_snake3.png")
GUISetState()
;game_init($width,$height,$tile_size,$map_width,$map_height,$map_x,$map_y,$default_value)
game_init($screen_width, $screen_height, 32, 10, 10,4, -11, 1)
;snake
;snake init
$snake_x = random(3,6,1)
$snake_y = random(3,6,1)
$snake_length = 1
dim $snake[$snake_length][2]
$snake[0][0] = $snake_x
$snake[0][1] = $snake_x
$snake_direction =Random(1,4,1)
$current_direction = $snake_direction
;const
const $direction_right = 1
const $direction_left = 2
const $direction_top = 3
const $direction_down = 4
$gift = false
$timer = TimerInit()
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
;tastatursteuerung pfeilasten recht,links,oben,unten
;~ If _IsPressed(25) Then
;~ $snake_direction = $direction_right
;~ ElseIf _IsPressed(27) Then
;~ $snake_direction = $direction_left
;~ EndIf
;~ If _IsPressed(26) Then
;~ $snake_direction = $direction_top
;~ ElseIf _IsPressed(28) Then
;~ $snake_direction = $direction_down
;~ EndIf
;~ ;tastatursteurung pfeiltasten rechts,links
If _IsPressed(25) Then
switch $current_direction
case $direction_right
$snake_direction = $direction_down
case $direction_left
$snake_direction = $direction_top
case $direction_top
$snake_direction = $direction_right
case $direction_down
$snake_direction = $direction_left
EndSwitch
ElseIf _IsPressed(27) Then
switch $current_direction
case $direction_right
$snake_direction = $direction_top
case $direction_left
$snake_direction = $direction_down
case $direction_top
$snake_direction = $direction_left
case $direction_down
$snake_direction = $direction_right
EndSwitch
EndIf
if TimerDiff($timer) >= 300 then
;moving
$before_x = $snake[0][0]
$before_y = $snake[0][1]
$current_direction = $snake_direction
switch $current_direction
case $direction_right
$before_x-=1
case $direction_left
$before_x+=1
case $direction_top
$before_y-=1
case $direction_down
$before_y+=1
EndSwitch
;add snake lengzh if gift collision
if game_map_get($before_x,$before_y) =3 then
$snake_length += 1
redim $snake[$snake_length][2]
$snake[$snake_length-1][0] = -1
$snake[$snake_length-1][1] = -1
game_map_set($before_x,$before_y,1)
$gift = false
endif
;collision
$find_collision = false
for $i = 0 to $snake_length-1
if $before_x = $snake[$i][0] and $before_y = $snake[$i][1] then
$find_collision = true
endif
Next
if $before_x < 0 or $before_x >= 10 or $before_y < 0 or $before_y >= 10 or $find_collision then
;restart
game_map_fill(1)
$snake_x = random(3,6,1)
$snake_y = random(3,6,1)
$snake_length = 1
dim $snake[$snake_length][2]
$snake[0][0] = $snake_x
$snake[0][1] = $snake_x
$snake_direction = Random(1,4,1)
$gift = false
$current_direction = $snake_direction
else
for $i = 0 to $snake_length-1
$xb = $before_x
$yb = $before_y
$before_x = $snake[$i][0]
$before_y = $snake[$i][1]
$snake[$i][0] = $xb
$snake[$i][1] = $yb
game_map_set($before_x,$before_y,1)
game_map_set($snake[$i][0],$snake[$i][1],2)
Next
endif
if not $gift then
;new gift
do
$giftx = random(0,9,1)
$gifty = random(0,9,1)
$find_collision = false
for $i = 0 to $snake_length-1
if $giftx = $snake[$i][0] and $gifty = $snake[$i][1] then
$find_collision = true
ExitLoop
endif
Next
Until not $find_collision
game_map_set($giftx,$gifty,3)
$gift = true
endif
$timer = TimerInit()
endif
;game_input($moveable_keyboard = false,$moveable_mouse = false,$clickable = false,$click_event = false)
game_input(false, false, false, false)
_GDIPlus_GraphicsClear($buffer, 0xffffffff)
;game_draw($buffer,$event_draw)
game_draw($buffer, draw_event)
_GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0)
Sleep(5)
WEnd
Func draw_event($x, $y, $value)
If $value = 1 Then
Return $tile1
ElseIf $value = 2 Then
Return $tile2
elseif $value = 3 Then
Return $tile3
EndIf
EndFunc ;==>draw_event
Alles anzeigen