Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 dodge type game? fix the AI movement should be fun!!!
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TokenHerbz




PostPosted: Sun Aug 13, 2017 6:47 am   Post subject: dodge type game? fix the AI movement should be fun!!!

arrow keys to move, shift to run. was just fartin around waiting for my PHP help Sad lol turings so old.
--------------
code:

View.Set ("graphics:800;500;nobuttonbar;position:center;center;title:demo")

class User
    export initialize, update_movement, draw, set_speed,
        get_speed_default, default_speed, collision_hit,
        get_x, get_y, get_size
     
    var user_speed, user_speed_default : int := 3
    var user_size : int
    var user_color : int
    var user_x, user_y: int

    proc initialize ( size_, color_, x_, y_ : int)
        user_size := size_
        user_color := color_
        user_x := x_
        user_y := y_
    end initialize

    proc boundry_check
        if user_x <= 0 then
            user_x := 0
        end if
        if user_y <= 0 then
            user_y := 0
        end if
        if user_x + user_size >= maxx then
            user_x := maxx - user_size
        end if       
        if user_y + user_size >= maxy then
            user_y := maxy - user_size
        end if
    end boundry_check
   
    proc update_movement (direction_: int)
    %% respectivly : UP/ DOWN/ LEFT/ RIGHT
        case direction_ of
            label 1 : user_y += user_speed
            label 2 : user_y -= user_speed
            label 3 : user_x -= user_speed
            label 4 : user_x += user_speed
        end case
        boundry_check
    end update_movement
   
    proc set_speed (speed_ : int)
        user_speed := speed_
    end set_speed
   
    proc default_speed
        user_speed := user_speed_default
    end default_speed

    proc draw
        Draw.FillBox(user_x, user_y, user_x + user_size, user_y + user_size, user_color)
    end draw

    function get_x : int
        result user_x
    end get_x
   
    function get_y : int
        result user_y
    end get_y
   
    function get_size : int
        result user_size
    end get_size
   
    function get_speed_default : int
        result user_speed_default
    end get_speed_default

    function collision_hit (enemy_x, enemy_y, enemy_s : int) : boolean
        if user_x + user_size >= enemy_x and
           user_x <= enemy_x + enemy_s and
           user_y + user_size >= enemy_y and
           user_y <= enemy_y + enemy_s then
           result true
        else
           result false
        end if
    end collision_hit   
end User

class Computer
    inherit User
    export auto_move
   
    %%fix this later to move better,
    proc auto_move
        for i: 1 .. 3
            update_movement(Rand.Int(1,4))
        end for
    end auto_move
end Computer

%game
var chars : array char of boolean
var spawn_distance_from_player := 50
var defeat: boolean := false

%%USER INIT
var player : pointer to User
new User, player
User(player).initialize(20,7,maxx div 2, maxy div 2)

%%ENEMIES
var enemy : flexible array 0 .. 0 of pointer to Computer
var enemy_size : int := 30

proc enemySpawn
    new enemy, upper(enemy) + 1
    new Computer, enemy(upper(enemy))
    var spawn_flag: boolean := false
    loop
        var x := Rand.Int(0,maxx - enemy_size)
        var y := Rand.Int(0,maxy - enemy_size)
       
        if (User(player).get_x + User(player).get_size + spawn_distance_from_player <= x or
                User(player).get_x - spawn_distance_from_player >= x + enemy_size) and
                (User(player).get_y + User(player).get_size + spawn_distance_from_player <= y or
                User(player).get_y - spawn_distance_from_player >= y + enemy_size) then
               
            spawn_flag := true
            Computer(enemy(upper(enemy))).initialize(enemy_size,42,x,y)
         end if 
         exit when spawn_flag
    end loop
end enemySpawn
enemySpawn

%%Game Loop
loop
    Draw.Cls

    if Rand.Int(0,100) < 2 then
        enemySpawn
    end if

    Input.KeyDown(chars)
    if chars(KEY_UP_ARROW) then
        User(player).update_movement(1)
    end if
    if chars(KEY_DOWN_ARROW) then
        User(player).update_movement(2)
    end if
    if chars(KEY_LEFT_ARROW) then
        User(player).update_movement(3)
    end if
    if chars(KEY_RIGHT_ARROW) then
        User(player).update_movement(4)
    end if
    if chars(KEY_SHIFT) then
        User(player).set_speed(User(player).get_speed_default * 3)
    else
        User(player).default_speed
    end if
   
    for e: 1 .. upper(enemy)
        Computer(enemy(e)).auto_move
        Computer(enemy(e)).draw
        if User(player).collision_hit(Computer(enemy(e)).get_x, Computer(enemy(e)).get_y, Computer(enemy(e)).get_size) then
            defeat := true
        end if
    end for   
    User(player).draw

    View.Update
    Time.Delay(20)
   
    if defeat then
       % exit
       Input.Pause
       for e: 1 .. upper(enemy)
           new enemy, upper(enemy) - 1
       end for
       defeat := false
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: