this would be the code you are looking for :) It will run by itself, but it is blitzbasic code
;Use the arrow keys
Graphics 640, 480, 0, 2
SetBuffer BackBuffer()
;how fast things fall
Const gravity# = .4
;make the level
Global level_image=CreateImage(500,400)
SetBuffer ImageBuffer(level_image);draw to level_image
Line 200,200,230,300
Rect 300,300,40,20
Rect 0,0,500-1,400-1,0
Oval 30,350,20,50
Line 420,340,500,340
Rect 333,122,30,40
Rect 100,200,40,5
Rect 40,150,10,40
Rect 470,280,30,30
SetBuffer BackBuffer()
;setup you
;where you are drawn
you_draw_x = GraphicsWidth()/2
you_draw_y = GraphicsHeight()/2
;how fast you are currently moving
you_speed_x# = 0
you_speed_y# = 0
;where the topleft of the screen is
screen_x# = 50
screen_y# = 50
;where you are in the level
you_x# = 0
you_y# = 0
;size of your collision rectangle
you_size_x = 20
you_size_y = 41
;##################################################
;MAIN LOOP
;##################################################
Repeat
If KeyHit(1) Then End
;move
you_speed_x = 0
If KeyDown(203) Then you_speed_x = -3
If KeyDown(205) Then you_speed_x = +3
;fall
you_speed_y = you_speed_y + gravity
;jump
If KeyHit(200) Then
;you must be on the ground to jump
If ImageRectCollide(level_image,0,0,0, you_x, you_y + 1, you_size_x, you_size_y) Then
you_speed_y = - 8
EndIf
EndIf
;stop speed if going to collide
If ImageRectCollide(level_image,0,0,0, you_x + you_speed_x, you_y, you_size_x, you_size_y) Then
you_speed_x = 0
EndIf
;move
screen_x = screen_x + you_speed_x
;stop speed if going to collide
If ImageRectCollide(level_image,0,0,0, you_x, you_y + you_speed_y, you_size_x, you_size_y) Then
you_speed_y = 0
EndIf
;move
screen_y = screen_y + you_speed_y
;screen_pos is at the top-left of the screen.
;so add your_draw_pos to it and that is where you are in the level
you_x = screen_x + you_draw_x
you_y = screen_y + you_draw_y
;DRAW LEVEL
DrawImage level_image,-screen_x,-screen_y
;draw you
Color 0, 255, 0
Rect you_draw_x, you_draw_y, you_size_x + 1, you_size_y + 1
Flip
Cls
Forever
|